home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 287_02 / graduser.doc < prev    next >
Encoding:
Text File  |  1989-05-23  |  178.6 KB  |  5,382 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                       GRAD Graphics Library User's Manual
  15.  
  16.                                  Version 1.1
  17.  
  18.  
  19.                         for IBM PC/XT/AT or compatibles
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.                                                        June 07, 1987
  36.  
  37.  
  38.                                                        By Conrad Kwok
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.                                Table of Contents
  57.  
  58.        
  59.        1   Introduction . . . . . . . . . . . . . . . . . . . . . .    1
  60.           1.1  General Information  . . . . . . . . . . . . . . . .    1
  61.           1.2  Licence  . . . . . . . . . . . . . . . . . . . . . .    2
  62.           1.3  Future Enhancements  . . . . . . . . . . . . . . . .    3
  63.        2   How to use GRAD  . . . . . . . . . . . . . . . . . . . .    4
  64.           2.1  Compile and Link . . . . . . . . . . . . . . . . . .    4
  65.           2.2  Interpretation . . . . . . . . . . . . . . . . . . .    6
  66.        3   The GRAD Frame . . . . . . . . . . . . . . . . . . . . .    7
  67.           3.1  Related Functions  . . . . . . . . . . . . . . . . .    7
  68.              3.1.1  CreateFrame . . . . . . . . . . . . . . . . . .    7
  69.              3.1.2  SelectFrame . . . . . . . . . . . . . . . . . .    8
  70.              3.1.3  RemvFrame . . . . . . . . . . . . . . . . . . .    8
  71.        4   Coordinate System  . . . . . . . . . . . . . . . . . . .   10
  72.           4.1  Physical Coordinate System . . . . . . . . . . . . .   10
  73.           4.2  Logical Coordinate System  . . . . . . . . . . . . .   10
  74.              4.2.1  Setting Origin  . . . . . . . . . . . . . . . .   10
  75.              4.2.2  Translation . . . . . . . . . . . . . . . . . .   11
  76.              4.2.3  Windowing . . . . . . . . . . . . . . . . . . .   11
  77.           4.3  Related Functions  . . . . . . . . . . . . . . . . .   11
  78.              4.3.1  SetOrg  . . . . . . . . . . . . . . . . . . . .   12
  79.              4.3.2  RelOrg  . . . . . . . . . . . . . . . . . . . .   12
  80.           4.4  Summary  . . . . . . . . . . . . . . . . . . . . . .   12
  81.        5   Setting Window . . . . . . . . . . . . . . . . . . . . .   13
  82.           5.1  Function Description . . . . . . . . . . . . . . . .   13
  83.              5.1.1  ResetWin  . . . . . . . . . . . . . . . . . . .   13
  84.              5.1.2  SetWin  . . . . . . . . . . . . . . . . . . . .   13
  85.           5.2  Example  . . . . . . . . . . . . . . . . . . . . . .   14
  86.        6   GRAD Environment . . . . . . . . . . . . . . . . . . . .   15
  87.           6.1  Functions Description  . . . . . . . . . . . . . . .   15
  88.              6.1.1  EnvSave . . . . . . . . . . . . . . . . . . . .   15
  89.              6.1.2  EnvRsto . . . . . . . . . . . . . . . . . . . .   16
  90.        7   Selection of Plot Type . . . . . . . . . . . . . . . . .   16
  91.           7.1  Related Function . . . . . . . . . . . . . . . . . .   17
  92.              7.1.1  PlotType  . . . . . . . . . . . . . . . . . . .   17
  93.        8   Dot Plotting and Line Drawing  . . . . . . . . . . . . .   18
  94.           8.1  Functions Description  . . . . . . . . . . . . . . .   18
  95.              8.1.1  Dot . . . . . . . . . . . . . . . . . . . . . .   18
  96.              8.1.2  SetStyle  . . . . . . . . . . . . . . . . . . .   18
  97.              8.1.3  HorzLine  . . . . . . . . . . . . . . . . . . .   19
  98.              8.1.4  VertLine  . . . . . . . . . . . . . . . . . . .   19
  99.           8.2  Efficiency Consideration . . . . . . . . . . . . . .   20
  100.        9   Circle, Ellipse and Arc  . . . . . . . . . . . . . . . .   21
  101.           9.1  Functions Description  . . . . . . . . . . . . . . .   21
  102.              9.1.1  Circle  . . . . . . . . . . . . . . . . . . . .   21
  103.              9.1.2  Ellipse . . . . . . . . . . . . . . . . . . . .   22
  104.              9.1.3  FillCircle  . . . . . . . . . . . . . . . . . .   22
  105.              9.1.4  FillEllipse . . . . . . . . . . . . . . . . . .   23
  106.              9.1.5  Arc1  . . . . . . . . . . . . . . . . . . . . .   23
  107.              9.1.6  Earc1 . . . . . . . . . . . . . . . . . . . . .   24
  108.              9.1.7  Arc2  . . . . . . . . . . . . . . . . . . . . .   25
  109.              9.1.8  Earc2 . . . . . . . . . . . . . . . . . . . . .   26
  110.              9.1.9  ArcPoint  . . . . . . . . . . . . . . . . . . .   27
  111.           9.2  Hints  . . . . . . . . . . . . . . . . . . . . . . .   27
  112.        10  4-connected Region Filling . . . . . . . . . . . . . . .   29
  113.           10.1  Functions Description . . . . . . . . . . . . . . .   29
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.              10.1.1  SolidFill  . . . . . . . . . . . . . . . . . .   29
  124.              10.1.2  PatternFill  . . . . . . . . . . . . . . . . .   30
  125.           10.2  Hints . . . . . . . . . . . . . . . . . . . . . . .   31
  126.        11  Text Characters Related Functions  . . . . . . . . . . .   32
  127.           Introduction  . . . . . . . . . . . . . . . . . . . . . .   32
  128.           11.1  Functions Description . . . . . . . . . . . . . . .   32
  129.              11.1.1  LoadFont . . . . . . . . . . . . . . . . . . .   32
  130.              11.1.2  SelectFont . . . . . . . . . . . . . . . . . .   33
  131.              11.1.3  RemvFont . . . . . . . . . . . . . . . . . . .   33
  132.              11.1.4  WriteStr . . . . . . . . . . . . . . . . . . .   34
  133.              11.1.5  ReadStr  . . . . . . . . . . . . . . . . . . .   36
  134.              11.1.6  NextXY . . . . . . . . . . . . . . . . . . . .   37
  135.        12  Block Operations . . . . . . . . . . . . . . . . . . . .   38
  136.           12.1  Function Description  . . . . . . . . . . . . . . .   38
  137.              12.1.1  BlockCopy  . . . . . . . . . . . . . . . . . .   38
  138.              12.1.2  BlockSave  . . . . . . . . . . . . . . . . . .   39
  139.              12.1.3  BlockLoad  . . . . . . . . . . . . . . . . . .   39
  140.        13  Frame Printing . . . . . . . . . . . . . . . . . . . . .   41
  141.           13.1  Function Description  . . . . . . . . . . . . . . .   41
  142.              13.1.1  PrintFrame . . . . . . . . . . . . . . . . . .   41
  143.        14  The DRAW function  . . . . . . . . . . . . . . . . . . .   44
  144.           14.1  Draw  . . . . . . . . . . . . . . . . . . . . . . .   44
  145.        15  Miscellaneous Functions  . . . . . . . . . . . . . . . .   48
  146.           15.1  Functions Description . . . . . . . . . . . . . . .   48
  147.              15.1.1  GRADinit . . . . . . . . . . . . . . . . . . .   48
  148.              15.1.2  cleanup  . . . . . . . . . . . . . . . . . . .   48
  149.              15.1.3  XHLine . . . . . . . . . . . . . . . . . . . .   49
  150.              15.1.4  writec . . . . . . . . . . . . . . . . . . . .   49
  151.        16  Advance Functions  . . . . . . . . . . . . . . . . . . .   51
  152.           16.1  Functions Description . . . . . . . . . . . . . . .   51
  153.              16.1.1  calcaddr . . . . . . . . . . . . . . . . . . .   51
  154.              16.1.2  exchange . . . . . . . . . . . . . . . . . . .   51
  155.              16.1.3  fr_read  . . . . . . . . . . . . . . . . . . .   52
  156.              16.1.4  fr_write . . . . . . . . . . . . . . . . . . .   52
  157.              16.1.5  phyaddr  . . . . . . . . . . . . . . . . . . .   52
  158.              16.1.6  writetype  . . . . . . . . . . . . . . . . . .   53
  159.        17  System Dependent Functions . . . . . . . . . . . . . . .   54
  160.           17.1  Functions Description . . . . . . . . . . . . . . .   54
  161.              17.1.1  settext  . . . . . . . . . . . . . . . . . . .   54
  162.              17.1.2  setgraph . . . . . . . . . . . . . . . . . . .   54
  163.              17.1.3  initjlsr . . . . . . . . . . . . . . . . . . .   54
  164.              17.1.4  cleanjlsr  . . . . . . . . . . . . . . . . . .   55
  165.              17.1.5  dumpjlsr . . . . . . . . . . . . . . . . . . .   55
  166.        18  GRAD Global Variables  . . . . . . . . . . . . . . . . .   56
  167.           18.1  TEN_MS  . . . . . . . . . . . . . . . . . . . . . .   56
  168.           18.2  DOTVALUE  . . . . . . . . . . . . . . . . . . . . .   56
  169.           18.3  PRE_GRAD_ERR_LEVEL, POST_GRAD_ERR_LEVEL . . . . . .   56
  170.           18.4  PRE_ERROR_FUNC, POST_ERROR_FUNC . . . . . . . . . .   56
  171.           18.5  SPACING_FUNC  . . . . . . . . . . . . . . . . . . .   57
  172.           18.6  XLIMIT, YLIMIT  . . . . . . . . . . . . . . . . . .   57
  173.           18.7  ORGX, ORGY  . . . . . . . . . . . . . . . . . . . .   57
  174.           18.8  WINX1, WINX2, WINY1, WINY2  . . . . . . . . . . . .   58
  175.        19  Advance Topics . . . . . . . . . . . . . . . . . . . . .   59
  176.           19.1  Error Handling  . . . . . . . . . . . . . . . . . .   59
  177.           19.2  Using SPACING_FUNC  . . . . . . . . . . . . . . . .   60
  178.        20  Sample Programs  . . . . . . . . . . . . . . . . . . . .   62
  179.           20.1  MPrint and Interp . . . . . . . . . . . . . . . . .   62
  180.           20.2  Rotate  . . . . . . . . . . . . . . . . . . . . . .   63
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.           20.3  Size  . . . . . . . . . . . . . . . . . . . . . . .   64
  191.           20.4  DispFont  . . . . . . . . . . . . . . . . . . . . .   64
  192.           20.5  SwPrt (Sideway) . . . . . . . . . . . . . . . . . .   64
  193.           20.6  Tex2GRAD  . . . . . . . . . . . . . . . . . . . . .   65
  194.        Appendix A : Customizing of Printer Control Codes  . . . . .   67
  195.           General Information . . . . . . . . . . . . . . . . . . .   67
  196.           EPSON FX-80 Driver Case Study . . . . . . . . . . . . . .   69
  197.           OKI ML192 Driver Case Study . . . . . . . . . . . . . . .   69
  198.           Additional Information  . . . . . . . . . . . . . . . . .   70
  199.        Appendix B : Customizing of Output Device  . . . . . . . . .   71
  200.        Appendix C : Font File Structure . . . . . . . . . . . . . .   72
  201.           Fixed Size Character (type 0) . . . . . . . . . . . . . .   72
  202.           Variable Size Character (type 1)  . . . . . . . . . . . .   73
  203.        Appendix D : Block File Structure  . . . . . . . . . . . . .   74
  204.        Appendix E : Functions Summary . . . . . . . . . . . . . . .   75
  205.        Appendix F : System Limits . . . . . . . . . . . . . . . . .   76
  206.           Program Limits  . . . . . . . . . . . . . . . . . . . . .   76
  207.           Configuration Limits  . . . . . . . . . . . . . . . . . .   76
  208.        Appendix G : Error Messages  . . . . . . . . . . . . . . . .   78
  209.        Appendix H : List of Header Files  . . . . . . . . . . . . .   79
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.        GRAD User's Manual                                    June 7, 1987
  256.  
  257.        1   Introduction
  258.  
  259.        1.1  General Information
  260.  
  261.             GRAD  is a  graphics functions library  for program compiled
  262.        with Microsoft  C  compiler  V4.0  in  small  model.  The library
  263.        contains most  functions  you  normally  expected  in  a graphics
  264.        library plus a number of unique features.
  265.             
  266.             This  brief summary is  to  introduce  you  features in GRAD
  267.        version 1.1. Each of these features is described in detail in the
  268.        documentation.
  269.             
  270.          a. GRAD  supports  color graphics  card  in 640  X 200 graphics
  271.             mode,  Hercules 720  X 348  graphics mode and JLASER (2560 X
  272.             3162). Other output device can be configured.
  273.          
  274.          b. It can create multiple  virtual screens of  very large size.
  275.             which  is  limited by  memory.  That  means  you  can create
  276.             graphics even you do not have a graphics display screen.
  277.          
  278.          c. Functions are provided to maintain windows.
  279.          
  280.          d. Nearly all  low  level  functions  are  written  in assembly
  281.             language to provide speed.  The result below  is obtained by
  282.             running the program BRENCH on an AT compatible (8MHz, 1 wait
  283.             state). All library functions when compiled with Microsoft C
  284.             compiler  use   8088   codes  option.   All   times  are  in
  285.             millisecond.
  286.          
  287.                                  Hercules Card         Virtual Screen
  288.             a loop                  0.0023               0.0023
  289.             Horizontal Line         0.38                 0.27
  290.              (length 300)
  291.             Horiz. Line width 20    6.2                  4.3
  292.             Vertical Line           8.5                  5.7
  293.              (length 300)
  294.             Vert. Line width 2      8.5                  5.7
  295.             Vert. Line width 32    17.0                 11.3
  296.             Circle radius 100      25.5                 28.3
  297.             Ellipse both axes
  298.                is 100 pixels       30.5                 33.3
  299.             
  300.             When drawing a horizontal line, it takes about 1 microsecond
  301.             per pixel on average!
  302.             
  303.          e. The  whole   library  use  integer   arithmetic  only.  This
  304.             guarantees  high speed operations when executed without math
  305.             coprocessor and keep the program size small.
  306.          
  307.          f. Besides simple functions such as dot,  line, circle, ellipse
  308.             ...etc., high speed arc drawing and region filling functions
  309.             are also included.
  310.          
  311.          g. Screen  printing is provided  as standard  function in GRAD.
  312.             Many  different  options  are  provided  such  as  different
  313.             printing density and mixed printing of text and graphics.
  314.          
  315.  
  316.                                       - 1 -
  317.  
  318.  
  319.  
  320.  
  321.  
  322.        GRAD User's Manual                                    June 7, 1987
  323.  
  324.          h. GRAD provides functions for high speed and high quality text
  325.             display.
  326.          
  327.          i. The whole screen or part of a screen can be saved, loaded or
  328.             copied.
  329.          
  330.             
  331.             Several sample  programs  with practical  value are included
  332.        such as  sideway printing  and text  and graphics  merge printing
  333.        programs.
  334.  
  335.        
  336.        1.2  Licence
  337.  
  338.             You may freely  copy  and distribute  the  GRAD  library and
  339.        related programs for non-commerical use only.
  340.  
  341.             If you find this library and the related  programs useful, a
  342.        contribution of  $20  or whatever  you  think  it  worth  will be
  343.        appreciated.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.                                       - 2 -
  367.  
  368.  
  369.  
  370.  
  371.  
  372.        GRAD User's Manual                                    June 7, 1987
  373.  
  374.             
  375.  
  376.  
  377.                 [EMPTY]
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.                                       - 3 -
  385.  
  386.  
  387.  
  388.  
  389.  
  390.        GRAD User's Manual                                    June 7, 1987
  391.  
  392.        2   How to use GRAD
  393.  
  394.             There are two ways to use the GRAD functions. The obvious is
  395.        to write a program that use  the GRAD functions  and then compile
  396.        and  link  with  GRAD  library.  Another way is  to  write a GRAD
  397.        command file that call GRAD  functions using syntax  similar to C
  398.        function call.  Then use the supplied program interp or Mprint to
  399.        interpret the file.
  400.             
  401.             The first way (compile and link) requires longer time but it
  402.        may use the full power of  C and GRAD  functions.  The second way
  403.        (interpretation)  limits the user to simple  graphics drawing but
  404.        the advantage is no compilation  and link is necessary.  Hence it
  405.        is good for simple drawings and debug a  drawing before including
  406.        in the final C program.
  407.             
  408.             The compile and link method will  be described  in detail in
  409.        this chapter.  The interpretation  method  will only be described
  410.        briefly in the chapter.  Details can be found in the user's guide
  411.        for interp and Mprint in the later chapter.
  412.             
  413.             Before we go on and try the first example,  I  want  to tell
  414.        you if you don't like to see any error message (in  text  form or
  415.        in bit mapped  form)  when the program is  in  graphics mode, you
  416.        want redirect  the output  from the file to  any file  you like.
  417.  
  418.        
  419.        2.1  Compile and Link
  420.  
  421.                
  422.                Knowledge of Microsoft C compiler Version  4.0 is
  423.                assumed and small model library must be installed
  424.                
  425.                
  426.             Below is a very  simple program  that draws a  dot only. Use
  427.        your  favorite  editor  to enter  the program below and  name the
  428.        program as "onedot.c".
  429.             
  430.                #include <stdio.h>
  431.                
  432.                main ()
  433.                {
  434.                        GradInit();     /* (1) */
  435.                        setgraph();     /* (2) */
  436.                        Dot(100,100);   /* (3) */
  437.                        getch();        /* (4) */
  438.                        settext();      /* (5) */
  439.                        cleanup(0);     /* (6) */
  440.                }
  441.  
  442.             Then compile and link the program using the command line:
  443.                cl /AS /J onedot.c /link GRADLIB
  444.             
  445.             If  you don't have  any typing  mistakes  and GRADLIB  is in
  446.        current  directory or  in  the  directory  specified  in  the LIB
  447.        environment variable,  you should get the file onedot.exe without
  448.  
  449.  
  450.  
  451.                                       - 4 -
  452.  
  453.  
  454.  
  455.  
  456.  
  457.        GRAD User's Manual                                    June 7, 1987
  458.  
  459.        getting an error message. If you get any error, go back and check
  460.        the program and make sure that the GRADLIB is properly installed.
  461.        Otherwise, you may go ahead and execute the program "onedot.exe".
  462.             
  463.             About one to two seconds  later,  the screen will be cleared
  464.        and you should find a single dot. Pressing any key will terminate
  465.        the program and the screen will return to text mode.
  466.             
  467.             Using the  GRAD library is simple.  Now let's  return to the
  468.        source listing and  examine it line by  line.  In the program, we
  469.        called 3  GRAD functions and 2 system dependent functions and 1 C
  470.        library function.
  471.  
  472.        (1) GRADinit is to initialize  the GRAD environment.  Now it only
  473.            performs a processor speed test and assign the result  to the
  474.            global  variable  TEN_MS.  Time  dependent  functions  may do
  475.            adjustment according to the  its value such  that they behave
  476.            the same on different speed computers. Actually we don't need
  477.            GRADinit in this case but  we should always  include that for
  478.            future compatibility.
  479.  
  480.        (2) setgraph is  not  a  standard  GRAD  function.  It  is system
  481.            dependent function.  It is only necessary if you  want to use
  482.            the default configured  graphics  screen.  Its function is to
  483.            change the display mode to graphics and clear the screen.
  484.  
  485.        (3) Dot is a GRAD function that  plot a  single dot. Dot(100,100)
  486.            means plot a dot at coordinate (100,100).
  487.  
  488.        (4) getch is a C library function that reads the next key pressed
  489.            on the keyboard.
  490.  
  491.        (5) settext  again is not a standard GRAD function. It is used to
  492.            change the display mode back to text mode.
  493.  
  494.        (6) cleanup is contrary to  GRADinit.  It should be called before
  495.            exit.  If the parameter to cleanup is  non-zero, cleanup will
  496.            execute  exit  with  the  parameter  as  exit  code.  If  the
  497.            parameter is zero, it will return to the caller.
  498.  
  499.        
  500.             Instead of using command line to do compile and link, we can
  501.        also use make file to do the same job. Below is an example:
  502.             
  503.                OPTIMIZE=/Ox
  504.                OPTIONS=/AS /J $(OPTIMIZE)
  505.                
  506.                .asm.obj:
  507.                        masm /ML $*;
  508.                
  509.                .c.obj:
  510.                        msc $(OPTION) $*;
  511.                
  512.                onedot.obj:     onedot.c
  513.                
  514.                onedot.exe:     onedot.obj
  515.                        link onedot,onedot,nul,GRADLIB;
  516.  
  517.  
  518.                                       - 5 -
  519.  
  520.  
  521.  
  522.  
  523.  
  524.        GRAD User's Manual                                    June 7, 1987
  525.  
  526.        2.2  Interpretation
  527.  
  528.             The one line  file  below will  perform exactly the  same as
  529.        our "onedot"  program in  the last  section  by  using  interp to
  530.        interpret it.
  531.             
  532.                Dot(100,100);
  533.             
  534.        Let's suppose the file above is called "onedot.gcm". To interpret
  535.        the file by interp, type
  536.  
  537.                interp onedot.gcm
  538.  
  539.        The syntax required by interp is described in a later chapter. 
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.                                       - 6 -
  586.  
  587.  
  588.  
  589.  
  590.  
  591.        GRAD User's Manual                                    June 7, 1987
  592.  
  593.        3   The GRAD Frame
  594.  
  595.             A frame is a memory area where the graphics image is stored.
  596.        It can be  any size  (there  are some  limitations and  they will
  597.        discuss in next section) but it must be an rectangle. Each bit of
  598.        the memory corresponds to a pixel.  The memory area  can be video
  599.        memory or  computer  working memory.  If it is video  memory, the
  600.        graphics image can be  seen on screen.  If it  is working memory,
  601.        the frame becomes a  virtual graphics screen.  The graphics image
  602.        can  only  be seen by  dumping  to the printer or  copying to the
  603.        video memory.
  604.             
  605.             More  than one  frame can exist simultaneously  within GRAD.
  606.        However  only one  frame can be  active at one time.  Usually the
  607.        graphics video memory is predefined  as the first  frame and this
  608.        is the default active frame. It is a permanent frame so it cannot
  609.        be removed by GRAD function RemvFrame which will be  described in
  610.        next section also.
  611.             
  612.             If you are the first time reading this manual,  you may skip
  613.        over this chapter and consider the video memory as the only frame
  614.        available. All functions that apply to the video memory frame can
  615.        be applied to the other frames in the same way.
  616.  
  617.        
  618.        3.1  Related Functions
  619.  
  620.        3.1.1  CreateFrame
  621.  
  622.                frame_number=CreateFrame(horizontal,vertical);
  623.                int frame_number, horizontal, vertical;
  624.  
  625.        RETURN VALUE
  626.             A frame number.
  627.  
  628.        DESCRIPTION
  629.  
  630.             The  CreateFrame  function  will  create  a  frame  of  size
  631.        specified by  the two parameters.  However,  the  horizontal size
  632.        must be an integral multiply of 16.  If it is not, the horizontal
  633.        size will be rounded up.
  634.             
  635.             Note that the maximum physical coordinate number will be one
  636.        less than the actual size because coordinate number starts at 0.
  637.  
  638.        POSSIBLE ERROR CONDITION
  639.  
  640.        a. Insufficient Memory
  641.           Program will terminate.
  642.           
  643.        b. Too many frame exist
  644.           The maximum number of frame allowed is an system parameter. If
  645.           the number is exceed, the program will terminate.
  646.           
  647.           
  648.        EXAMPLE
  649.  
  650.                frame=CreateFrame(640,200);
  651.  
  652.                                       - 7 -
  653.  
  654.  
  655.  
  656.  
  657.  
  658.        GRAD User's Manual                                    June 7, 1987
  659.  
  660.  
  661.        FUNCTIONS INCLUDED
  662.  
  663.                RemvFrame
  664.  
  665.        
  666.        3.1.2  SelectFrame
  667.  
  668.                ret=SelectFrame(frame);
  669.                int ret, frame;
  670.  
  671.        RETURN VALUE
  672.  
  673.             It  will  return  the active  frame number  just  before the
  674.        execution of SelectFrame if frame  number given is valid  and the
  675.        frame exist.  Otherwise -1  will be returned and the active frame
  676.        is not changed.
  677.             
  678.        DESCRIPTION
  679.             
  680.             The function  SelectFrame select  the current  active frame.
  681.        Furthermore, the drawing window and point of origin will reset to
  682.        the same as last time when the frame is deselected.  If the frame
  683.        is the first time selected after it  is created,  the origin will
  684.        be physical coordinate (0,0)  and the window size is same  as the
  685.        frame size.
  686.             
  687.        EXAMPLE
  688.  
  689.                if ((old_frame=SelectFrame(frame))==(-1))
  690.                        printf("Frame does not exist\n");
  691.                  .   .   .
  692.                  .   .   .   Draw in the new frame
  693.                  .   .   .
  694.                SelectFrame(old_frame);  /* switch back to the */
  695.                                         /* original frame     */
  696.  
  697.        FUNCTIONS INCLUDED
  698.  
  699.                SelectFont
  700.  
  701.        
  702.        3.1.3  RemvFrame
  703.  
  704.                ret=RemvFrame(frame);
  705.                int ret, frame;
  706.  
  707.        RETURN VALUE
  708.  
  709.             A return value of 0  means successful.  A return value of -1
  710.        means the frame does not exist. If the frame type is permanent, 0
  711.        will be returned but the frame can still be selected.
  712.  
  713.        DESCRIPTION
  714.  
  715.             The function RemvFrame will remove the frame  from GRAD. The
  716.        memory occupied by the frame will be deallocated.
  717.             
  718.  
  719.                                       - 8 -
  720.  
  721.  
  722.  
  723.  
  724.  
  725.        GRAD User's Manual                                    June 7, 1987
  726.  
  727.        EXAMPLE
  728.  
  729.                If (RemvFrame(frame)==(-1))
  730.                        printf("Frame does not exist\n");
  731.  
  732.        FUNCTIONS INCLUDED
  733.  
  734.                CreateFrame
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.                                       - 9 -
  787.  
  788.  
  789.  
  790.  
  791.  
  792.        GRAD User's Manual                                    June 7, 1987
  793.  
  794.        4   Coordinate System
  795.  
  796.        4.1  Physical Coordinate System
  797.  
  798.             Each Frame can be viewed as a two dimensional plane composes
  799.        of identical rectangular pixels.  Each pixel  is  in  of  the two
  800.        states --  on  or  off (set  or reset).  If a pixel is on,  it is
  801.        represented by a dot on screen or  on printer paper  or a logical
  802.        high state in memory.
  803.             
  804.             To address a pixel,  we can use x and  y coordinate numbers.
  805.        It  is usually  represented as (x,y).  the top right  corner of a
  806.        frame is defined as the origin of the physical  coordinate system
  807.        which  as  0  x  and  y  coordinate  value  (i.e.  (0,0)).  The x
  808.        coordinate of a pixel on the same horizontal line increase  as we
  809.        move right. The y coordinate of a pixel on the same vertical line
  810.        increase  as  we  move  downwards.  This  is  different  from the
  811.        coordinate system we usually used which has y coordinate increase
  812.        as we move upwards.
  813.             
  814.             The maximum value of the coordinate  numbers are  limited by
  815.        the size  of a  frame.  For example,  the number of pixels on IBM
  816.        color graphics adapter  are 640  (horizontal) and 200 (vertical).
  817.        Therefore legal x and y coordinate numbers are 0  to 639 and 0 to
  818.        199 respectively.
  819.             
  820.             Physical coordinate  numbers are only  used  in one external
  821.        interface function.  All  other functions use  logical coordinate
  822.        numbers which will be described in the next section.
  823.  
  824.        
  825.        4.2  Logical Coordinate System
  826.  
  827.             Logical coordinate system provides a convenient way  to look
  828.        at your frame.  Initially, the logical coordinate numbers are the
  829.        same as the physical coordinate  number.  The relationship can be
  830.        changed using SetOrg and RelOrg functions which will be described
  831.        later.
  832.             
  833.             The  relationship  between logical  and  physical coordinate
  834.        system can be  described in  several ways  and  different  way of
  835.        thinking helps in  different situation.  So  I will  describe all
  836.        three ways I can think of.
  837.  
  838.        
  839.        4.2.1  Setting Origin
  840.  
  841.             The logical coordinate  system  has  the  same  size  as the
  842.        physical coordinate  system.  Each pixel is one-one corresponding
  843.        between the two systems. The difference is that any pixels within
  844.        the logical coordinate system can  be defined as the  origin.
  845.             
  846.             Suppose your  frame size  is  640  by  200.  You  can define
  847.        (300,100)  in  physical  coordinate  system as the origin  in the
  848.        logical coordinate system.  The legal range of logical coordinate
  849.        numbers  will be  -320  to +319  and -100  to +99 for the x and y
  850.        coordinates respectively.  Any attempt to write outside the legal
  851.        space will be ignored.
  852.  
  853.                                      - 10 -
  854.  
  855.  
  856.  
  857.  
  858.  
  859.        GRAD User's Manual                                    June 7, 1987
  860.  
  861.             
  862.             
  863.             It is  legal to  define  a point  outside  the physical
  864.             coordinate system as the origin.  For  example, you can
  865.             define (-10,-10) as the origin. Legal coordinate number
  866.             for  x and y axes  will  be  10  to  649  and 10 to 209
  867.             respectively.
  868.             
  869.  
  870.        
  871.        4.2.2  Translation
  872.  
  873.             The logical and physical  coordinate  numbers are  offset by
  874.        fixed numbers specified by you.
  875.             
  876.             An  example of  this  situation  is  when  several identical
  877.        figures are required to draw on the frame.  Instead of  repeating
  878.        the  calling sequence  with different coordinate numbers,  we can
  879.        create a  subroutine  including  the  functions  for  drawing one
  880.        figure. We call the same subroutine as many times as required and
  881.        set different translation values in between two calls.
  882.  
  883.        
  884.        4.2.3  Windowing
  885.  
  886.             Try to imagine you are standing before a large square dinner
  887.        table. On the table, there is a piece of paper (normal size) with
  888.        its sides parallel to the edges of the table.  You are  holding a
  889.        special pen will only leave mark on the paper only but not on the
  890.        table.  You can draw anywhere  on the table.  However, only those
  891.        drawings passing the paper can be seen.
  892.             
  893.             This is an analogy of the relationship  between the physical
  894.        and  logical coordinate system.  The dinner table  is the logical
  895.        coordinate  system space,  the paper is  the  physical coordinate
  896.        system (or frame)  and the GRAD  functions are the  pen.  You can
  897.        place the frame anywhere within the logical coordinate space.
  898.             
  899.             The x and y coordinate  numbers  in  the  logical coordinate
  900.        space must be in the range of -32768 to +32767.
  901.  
  902.        
  903.        4.3  Related Functions
  904.  
  905.             There are two functions for the  control  of  the coordinate
  906.        system. They are:
  907.             
  908.             SetOrg(x,y) Set the point (x,y) in the physical coordinate
  909.                         system as the origin in the logical coordinate
  910.                         system.
  911.             
  912.             RelOrg(x,y) Set the point (x,y) in the logical coordinate 
  913.                         system as the new origin in the logical 
  914.                         coordinate system.
  915.  
  916.        
  917.  
  918.  
  919.  
  920.                                      - 11 -
  921.  
  922.  
  923.  
  924.  
  925.  
  926.        GRAD User's Manual                                    June 7, 1987
  927.  
  928.        4.3.1  SetOrg
  929.  
  930.                SetOrg(x,y);
  931.                int x,y;
  932.  
  933.        a. If you consider the logical coordinate system as  described in
  934.           4.2.1,  to set (x,y) as the origin, the function call required
  935.           is:
  936.                SetOrg(x,y);
  937.  
  938.        b. If you consider the logical coordinate system  as described in
  939.           4.2.2,  to set a and b pixels of  translation in x  and y axes
  940.           will require the function call:
  941.                SetOrg(a,b);
  942.  
  943.        c. If you consider the logical coordinate  system as described in
  944.           4.2.3 and you want to place the upper left corner of the frame
  945.           at (u,v) of the logical space, the function call required is:
  946.                SetOrg(-u,-v);
  947.  
  948.        FUNCTIONS INCLUDED
  949.  
  950.                RelOrg, SetWin, ResetWin
  951.  
  952.        
  953.        4.3.2  RelOrg
  954.  
  955.             The function of RelOrg is exactly the same  as SetOrg except
  956.        the parameter specified is add to the existing setting instead of
  957.        replacing the settings.
  958.  
  959.        
  960.        4.4  Summary
  961.  
  962.             All coordinate  number  described in  this  manual except in
  963.        this chapter  are  logical  coordinate  numbers  unless otherwise
  964.        specified. Initially, the physical and logical coordinate numbers
  965.        are the  same.  If you do not change it  by one  of the functions
  966.        SetOrg and RelOrg, they are equivalent.
  967.             
  968.             The x coordinate number increase as it move to the right and
  969.        the y  coordinate number increase  as it move  downwards. The top
  970.        left corner  of  a frame is  the  origin  (0,0)  of  the physical
  971.        coordinate system.
  972.             
  973.             
  974.             
  975.             
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                      - 12 -
  988.  
  989.  
  990.  
  991.  
  992.  
  993.        GRAD User's Manual                                    June 7, 1987
  994.  
  995.        5   Setting Window
  996.  
  997.             Windowing is one of the most important  features provided in
  998.        GRAD.  Every function described  in this manual  which may change
  999.        the  frame in  any way is  affected  by the  window setting. Only
  1000.        those  changes which are inside  the  window  are  permitted. Any
  1001.        attempt to change any pixels outside the window are ignored.
  1002.             
  1003.             The pixels outside the window  are essentially  frozen. They
  1004.        are unable to change the state until they are un-frozen.
  1005.             
  1006.             Therefore it is easy to create several windows in  the frame
  1007.        which  are  logically  separated  from  each  others. Furthermore
  1008.        additional  routines  are provided  to facilitate the  writing of
  1009.        application which need to maintain several window in the frame.
  1010.             
  1011.             A  simple  example of  creating and  maintaining windows are
  1012.        included later in this chapter.
  1013.             
  1014.             Only 2  functions in GRAD are directly related  to windowing
  1015.        (but most functions in GRAD are indirectly  related to  it). They
  1016.        are:
  1017.                
  1018.                ResetWin        Reset the window size to frame size
  1019.                SetWin          Set the window to the desired size
  1020.  
  1021.        
  1022.        5.1  Function Description
  1023.  
  1024.        5.1.1  ResetWin
  1025.  
  1026.                ResetWin()
  1027.  
  1028.        RETURN VALUE
  1029.             none
  1030.             
  1031.        DESCRIPTION
  1032.             
  1033.             Reset the window size to the current frame size.
  1034.             
  1035.        EXAMPLE
  1036.  
  1037.                ResetWin();
  1038.  
  1039.        FUNCTIONS INCLUDED
  1040.             SetWin, SetOrg, RelOrg
  1041.  
  1042.        
  1043.        5.1.2  SetWin
  1044.  
  1045.                SetWin(x1,y1,x2,y2);
  1046.                int x1,y2,x2,y2;
  1047.  
  1048.        RETURN VALUE
  1049.             none
  1050.             
  1051.        DESCRIPTION
  1052.             
  1053.  
  1054.                                      - 13 -
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.        GRAD User's Manual                                    June 7, 1987
  1061.  
  1062.             A window must be rectangular  in shape.  (x1,y1) and (x2,y2)
  1063.        are coordinates of the opposite corners of the  window. The order
  1064.        is not  important.  Both (x1,y1)  and (x2,y2) are included in the
  1065.        window.
  1066.             
  1067.             If (x1,y1)  and/or (x2,y2)  is/are  outside  the  frame, the
  1068.        window set will be the area of the window within the frame.
  1069.             
  1070.        EXAMPLE
  1071.  
  1072.                SetWin(100,100,200,200);
  1073.  
  1074.             The width and height of the window are both 101 pixels.
  1075.             
  1076.        FUNCTIONS INCLUDED
  1077.             ResetWin, RelOrg, SetOrg
  1078.  
  1079.        
  1080.        5.2  Example
  1081.  
  1082.        /* Below is code segment in C demostrating the use of window. */
  1083.        /* Some of the functions are not yet discussed. So you may    */
  1084.        /* wish to skip this section for the first reading.           */
  1085.  
  1086.        ResetWin();
  1087.        PlotType(1);
  1088.        HorzLine(-10000,-10000,20000,20000);  /* Clear Frame */
  1089.        PlotType(0);    /* select OR type */
  1090.        SetOrg(99,19);  
  1091.        Rectangle(0,0,203,103); /* A rectangle enclosing the window */
  1092.        RelOrg(1,1);    /* top-left-hand corner of the window */
  1093.        SetWin(0,0,200,100);    /* set window */
  1094.        window1=EnvSave(0);     /* save all the environment setting */
  1095.        SetOrg(400,20);         /* move to the second window */
  1096.        SetWin(0,0,100,100);    /* set window */
  1097.        HorzLine(0,0,1000,1000); /* Set all the pixels inside window */
  1098.        PlotType(1);            /* select AND type */
  1099.        window2=EnvSave(0);     /* save all the settings */
  1100.  
  1101.        Circle(50,50,80); /* setting is not affected, draws in window2 */
  1102.        Line(0,0,200,200); 
  1103.        Line(100,0,0,100);
  1104.  
  1105.        EnvRsto(window1,KEEP_SLOT); /* restore environment of window1 */
  1106.        WriteStr(0,LEFT,0,10,
  1107.              "The drawing in this frame is completely unaffected",0,0);
  1108.        WriteStr(0,LEFT,0,20,
  1109.              "By the drawing in the other frame.",0,0);
  1110.  
  1111.        EnvRsto(window2,KEEP_SLOT); /* back to window2 */
  1112.        SolidFill(40,50);
  1113.  
  1114.        EnvRsto(window1,KEEP_SLOT); /* back to window1 */
  1115.        WriteStr(0,LEFT,0,50,
  1116.              "You may switch back and forth between the 2 window",0,0);
  1117.  
  1118.        
  1119.  
  1120.  
  1121.                                      - 14 -
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.        GRAD User's Manual                                    June 7, 1987
  1128.  
  1129.        6   GRAD Environment
  1130.  
  1131.             Several parameters of GRAD has global effect.  For examples,
  1132.        plot type,  frame  number,  window setting,  ...et  cetera. These
  1133.        settings are called the environment of GRAD.
  1134.             
  1135.             Sometimes,  one  may wish  to  save  the current environment
  1136.        settings and restore it later. For instances when several windows
  1137.        are using at the same time.
  1138.             
  1139.             GRAD  provides  two  functions  to  save  and  restore these
  1140.        environment settings. You may selectively restore some or all the
  1141.        settings. Those two functions are:
  1142.  
  1143.                EnvSave         Save the current environment
  1144.                EnvRsto         Restore the environment saved
  1145.  
  1146.        
  1147.        6.1  Functions Description
  1148.  
  1149.        6.1.1  EnvSave
  1150.  
  1151.                EnvSave(slot_nu);
  1152.                int slot_nu;
  1153.  
  1154.        RETURN VALUE
  1155.             0  means no more slot  available.  All other positive number
  1156.        means environment is save in the that slot number.
  1157.  
  1158.        DESCRIPTION
  1159.  
  1160.             slot_nu can be from 0 to the maximum slot number. If slot_nu
  1161.        number is 0,  EnvSave will search for an  empty slot.  If none is
  1162.        found,  0 will be returned otherwise the slot number used will be
  1163.        returned.
  1164.             
  1165.             When a slot  number  is  given,  current environment will be
  1166.        saved in  that  slot  number  even  if  that  slot  is used. This
  1167.        provides  a  means  to  dedicate  a  certain  slot  number  for a
  1168.        particular application.  Contents can be changed without worrying
  1169.        about any change of slot number.
  1170.             
  1171.             The following settings  are save  by  EnvSave: frame number,
  1172.        window coordinates, origin, plot type, style and font number.
  1173.             
  1174.             EnvSave will not change any of the settings.
  1175.             
  1176.        Note : When you change active frame,  both the  origin and window
  1177.               setting are saved.  When  the frame  is  re-selected, they
  1178.               will be restored. See also SelectFrame
  1179.  
  1180.        EXAMPLES
  1181.                EnvSave(0);
  1182.  
  1183.             Save the current environment in the next unused slot.
  1184.  
  1185.        FUNCTIONS INCLUDED
  1186.             EnvRsto
  1187.  
  1188.                                      - 15 -
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.        GRAD User's Manual                                    June 7, 1987
  1195.  
  1196.        6.1.2  EnvRsto
  1197.  
  1198.                EnvRsto(slot_nu, options);
  1199.                int slot_nu, options;
  1200.  
  1201.        RETURN VALUE
  1202.             none
  1203.  
  1204.        DESCRIPTION
  1205.  
  1206.             EnvRsto will  restore all  or  partial  environment settings
  1207.        saved in the slot.  The slot number should be a value returned by
  1208.        EnvSave.  However,  slot number  0  has special meaning.  If 0 is
  1209.        given,  the environment settings at the time when  the program is
  1210.        first started are restored.
  1211.             
  1212.             The default options are to restore all  settings and release
  1213.        the  slot.  You  may change  the default by  using  the following
  1214.        options.  (The definition of the option can be found in  the file
  1215.        GRADENV.H)
  1216.          
  1217.          KEEP_SLOT     do not release the slot
  1218.          KEEP_WIN      keep the current window setting
  1219.          KEEP_ORG      keep the current origin
  1220.          KEEP_STYLE    keep the current plot style
  1221.          KEEP_PLOTTYPE keep the current plot type
  1222.          KEEP_FRAME    keep the current active frame
  1223.          KEEP_FONT     keep the current font
  1224.          
  1225.             To combine more than 1 options, use bitwise OR operator '|'.
  1226.  
  1227.        EXAMPLE
  1228.                EnvRsto(0);
  1229.  
  1230.             Restore all default settings.
  1231.             
  1232.        FUNCTIONS INCLUDED
  1233.             EnvSave
  1234.  
  1235.        
  1236.        7   Selection of Plot Type
  1237.  
  1238.             Each pixel in the frame must be in one of the two  states --
  1239.        either set or reset. When GRAD draws in the frame, it can force a
  1240.        pixel to set or reset or reverse the state.  In GRAD terminology,
  1241.        the three types of operations are  called OR,  AND and XOR. Their
  1242.        function codes are 0, 1 and 2 respectively.
  1243.             
  1244.           Code    Type         Description
  1245.            0       OR          Force a pixel to set state
  1246.            1       AND         Force a pixel to reset state
  1247.            2       XOR         Reverse the state of a pixel
  1248.           
  1249.           
  1250.             Every GRAD function which draws to the frame  is affected by
  1251.        the current plot type.  The default plot type is OR.  The name of
  1252.        the function to  change the plot type  is PlotType which  will be
  1253.        described in next section.
  1254.  
  1255.                                      - 16 -
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.        GRAD User's Manual                                    June 7, 1987
  1262.  
  1263.        7.1  Related Function
  1264.  
  1265.        7.1.1  PlotType
  1266.  
  1267.                ret=PlotType(type);
  1268.                int ret, type;
  1269.  
  1270.        RETURN VALUE
  1271.             The plot type (between 0 and 3) used before this function is
  1272.        executed.
  1273.             
  1274.        DESCRIPTION
  1275.             Set the plot type according to the table below:
  1276.             
  1277.           Code    Type         Description
  1278.            0       OR          Force a pixel to set state
  1279.            1       AND         Force a pixel to reset state
  1280.            2       XOR         Reverse the state of a pixel
  1281.            3       OR          same as type 0
  1282.             
  1283.             If the type specified is greater than  3,  then it will take
  1284.        module 4 of the value given and set according to the table above.
  1285.             
  1286.        EXAMPLE
  1287.  
  1288.                PlotType(0);
  1289.  
  1290.        FUNCTIONS INCLUDED
  1291.  
  1292.                none
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.                                      - 17 -
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.        GRAD User's Manual                                    June 7, 1987
  1329.  
  1330.        8   Dot Plotting and Line Drawing
  1331.  
  1332.             This chapter will describe the following functions:
  1333.             
  1334.             Dot(x,y)
  1335.                Plot a single dot
  1336.             
  1337.             SetStyle(style)
  1338.                Set the line style
  1339.             
  1340.             HorzLine(x,y,length,width)
  1341.                Draws  a  horizontal  line  starting  from  (x,y)  in the
  1342.                direction of increasing x.  The width of the  line extend
  1343.                in the direction of increasing y.
  1344.                
  1345.             VertLine(x,y,length,width)
  1346.                Draws  a  vertical  line  starting  from   (x,y)  in  the
  1347.                direction of increasing y.  The width of  the line extend
  1348.                in the direction of increasing x.
  1349.  
  1350.        
  1351.        8.1  Functions Description
  1352.  
  1353.        8.1.1  Dot
  1354.  
  1355.                Dot(x,y);
  1356.                int x,y;
  1357.  
  1358.        RETURN VALUE
  1359.             none
  1360.  
  1361.        DESCRIPTION
  1362.             It plot a dot at location (x,y) of current active frame.
  1363.  
  1364.        EXAMPLE
  1365.  
  1366.                Dot(10,10)
  1367.  
  1368.        FUNCTIONS INCLUDED
  1369.  
  1370.             HorzLine, VertLine
  1371.  
  1372.        
  1373.        8.1.2  SetStyle
  1374.  
  1375.                old=SetStyle(style);
  1376.                unsigned int style, old;
  1377.  
  1378.        RETURN VALUE
  1379.             return the old style setting
  1380.             
  1381.        DESCRIPTION
  1382.             
  1383.             It sets the style of the line  drawn by  HorzLine, VertLine,
  1384.        Line,  Arc1,  Arc2,  Earc1  and Earc2.  Style is  a 16-bit value.
  1385.        Default is  0xffff.  That means the lines drawn  are  solid line.
  1386.        When you call SetStyle,  it just move the value  of the parameter
  1387.  
  1388.  
  1389.                                      - 18 -
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.        GRAD User's Manual                                    June 7, 1987
  1396.  
  1397.        to a internal variable except when the value is 0.  In that case,
  1398.        the  original  value will  be  inverted.  (i.e. exclusive or with
  1399.        0xffff).
  1400.             
  1401.        EXAMPLES
  1402.                oldstyle=SetStyle(0xffff);      /* save original style */
  1403.                HorzLine(0,0,100,1);
  1404.                SetStyle(0x3333);
  1405.                HorzLine(0,10,100,1);
  1406.                SetStyle(0);
  1407.                HorzLine(0,20,100,1);
  1408.                SetStyle(0x11ff);
  1409.                HorzLine(0,30,100,1);
  1410.                SetStyle(oldstyle);     /* restore original style */
  1411.             
  1412.             
  1413.             The first line is a solid line. The second and third example
  1414.        draw 2  dotted lines with 2 dots in every 4 dot position. However
  1415.        the ink dots position are complementary of each other. The fourth
  1416.        example draw a mixed of dotted and dashed line.
  1417.             
  1418.        FUNCTIONS INCLUDED
  1419.  
  1420.                none
  1421.  
  1422.        
  1423.        8.1.3  HorzLine
  1424.  
  1425.                HorzLine(x,y,length,width);
  1426.                int x,y,length,width;
  1427.  
  1428.        RETURN VALUE
  1429.             none
  1430.  
  1431.        DESCRIPTION
  1432.             It  draws  a  horizontal  line  (i.e.  parallel  to  x axis)
  1433.        starting from  the point (x,y)  in the increasing  direction of x
  1434.        coordinate. If the length or width is less than or equal to zero,
  1435.        nothing will be drawn.  The width of the line will extend  in the
  1436.        increasing direction of y coordinate.  The line drawn is affected
  1437.        by the style set by SetStyle.
  1438.             
  1439.        EXAMPLE
  1440.                HorzLine(100,100,100,2);
  1441.             
  1442.             Draws a line of length 100 pixels and width is 2. That means
  1443.        a total of 200 pixels are drawn.
  1444.             
  1445.        FUNCTIONS INCLUDED
  1446.                Dot, VertLine
  1447.  
  1448.        
  1449.        8.1.4  VertLine
  1450.  
  1451.                VertLine(x,y,length,width);
  1452.                int x,y,length,width;
  1453.  
  1454.        RETURN VALUE
  1455.  
  1456.                                      - 19 -
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.        GRAD User's Manual                                    June 7, 1987
  1463.  
  1464.             none
  1465.  
  1466.        DESCRIPTION
  1467.             It draws a vertical line (i.e.  parallel to y axis) starting
  1468.        from the point (x,y) in the increasing direction of y coordinate.
  1469.        If the length  or  width is less than  or equal  to zero, nothing
  1470.        will be drawn.  The width of the line  extends in  the increasing
  1471.        direction  of  x coordinate.  The  line drawn is affected  by the
  1472.        STYLE set by SetStyle.
  1473.             
  1474.        EXAMPLE
  1475.                VertLine(100,100,100,2);
  1476.             
  1477.             Draws a line of length 100 pixels and width is 2. That means
  1478.        a total of 200 pixels are drawn.
  1479.             
  1480.        FUNCTIONS INCLUDED
  1481.                Dot, HorzLine
  1482.  
  1483.        
  1484.  
  1485.        8.2  Efficiency Consideration
  1486.  
  1487.             HorzLine and VertLine never call Dot to draw  line. They use
  1488.        a much faster method to draw line.  Therefore,  it is much longer
  1489.        to plot 100 consecutive dots than draw a 100 pixels long vertical
  1490.        or horizontal line.
  1491.             
  1492.             HorzLine  in general  draws faster than VertLine  in drawing
  1493.        lines with same length and width. Therefore if you want to draw a
  1494.        block with length and width approximately the same,  it is better
  1495.        to use HorzLine. However, if the style setting is not 0xffff, the
  1496.        result by HorzLine and VertLine are different.
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.                                      - 20 -  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.        GRAD User's Manual                                    June 7, 1987
  1530.  
  1531.        9   Circle, Ellipse and Arc
  1532.  
  1533.             GRAD library provides extensive support for drawing circles,
  1534.        ellipses and arcs.
  1535.             
  1536.             The  circle command  in some programs  or libraries actually
  1537.        draws a polygon.  That  may look  like a circle when  the desired
  1538.        circle is small. But when the desired circle is large, the output
  1539.        will not be a circle any more.
  1540.             
  1541.             The circle and ellipse function in GRAD draw  `true' circles
  1542.        and ellipses. What it means is then the circles and ellipses when
  1543.        displayed  or  printed on  a media with  aspect ratio  equal to 1
  1544.        (i.e.  the width and height of a pixel is  equal),  each pixel of
  1545.        the  circles or  ellipses  is  less  than or equal to  half pixel
  1546.        distance from  a real  circle  or  ellipse  with  the  same size.
  1547.        Furthermore,  each pixel will be adjacent to 2  and only 2 pixels
  1548.        of the circle  or ellipse.  So the region enclosed can  be filled
  1549.        using the fill command.
  1550.             
  1551.             The functions that will be described in this chapter are:
  1552.                Circle          Draws a logical circle
  1553.                Ellipse         Draws a logical ellipse
  1554.                FillCircle      Draws a disc
  1555.                FillEllipse     Draws a elliptical disc
  1556.                Arc1            Arc drawing 1
  1557.                Earc1           Elliptical arc drawing 1
  1558.                Arc2            Arc drawing 2
  1559.                Earc2           Elliptical arc drawing 2
  1560.                ArcPoint        Gives the coordinates of 2 end points
  1561.                                of Arc2 or Earc2
  1562.                
  1563.             Since the aspect ratio of  the output  device may  not be 1.
  1564.        The circle drawn by Circle may not look like a  circle on output.
  1565.        If  you want to get `circle'  in  the output,  you should draw an
  1566.        ellipse with  appropriate  ratio of horizontal  and vertical axes
  1567.        specified.  For example,  the width of  a pixel is  twice  of the
  1568.        height of the pixel on a certain output device. In order to get a
  1569.        `circle', the length of the horizontal axis should be half of the
  1570.        vertical axis.
  1571.  
  1572.        
  1573.        9.1  Functions Description
  1574.  
  1575.        9.1.1  Circle
  1576.  
  1577.                Circle(center_x, center_y, radius);
  1578.                int center_x, center_y, radius;
  1579.  
  1580.        RETURN VALUE
  1581.             none
  1582.  
  1583.        DESCRIPTION
  1584.  
  1585.             This function will draw a logical circle.  radius is in term
  1586.        of pixels and must be greater than or equal to 0. The circle draw
  1587.        is  not affected  by the plot style setting.  (See  also Arc1 and
  1588.        Arc2)
  1589.  
  1590.                                      - 21 -
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.        GRAD User's Manual                                    June 7, 1987
  1597.  
  1598.             
  1599.        EXAMPLE
  1600.  
  1601.                Circle(100,100,20);
  1602.  
  1603.             Assume the window is larger than  the circle.  Then the left
  1604.        most,  right most,  top and bottom points  of the  circle will be
  1605.        (80,100), (120,100), (100,80) and (100,120) respectively.
  1606.  
  1607.        FUNCTIONS INCLUDED
  1608.             Arc1
  1609.  
  1610.        
  1611.        9.1.2  Ellipse
  1612.  
  1613.                Ellipse(center_x, center_y, horiz_axis, vert_axis);
  1614.                int center_x, center_y, horiz_axis, vert_axis;
  1615.  
  1616.        RETURN VALUE
  1617.             none
  1618.  
  1619.        DESCRIPTION
  1620.  
  1621.             This  function  will  draw  an  ellipse.  horiz_axis  is the
  1622.        distance in pixel from the center to the left most or  right most
  1623.        point of the ellipse.  vert_axis is the distance from  the center
  1624.        to the top or  bottom  point of  the ellipse.  If  horiz_axis and
  1625.        vert_axis is equal,  the result will be the same as  using Circle
  1626.        will radius  set to  either horiz_axis or  vert_axis. The ellipse
  1627.        drawn  is  not affected  by the  plot style.  (See also Earc1 and
  1628.        Earc2)
  1629.             
  1630.        EXAMPLE
  1631.  
  1632.                Ellipse(100,100,40,20);
  1633.  
  1634.        FUNCTIONS INCLUDED
  1635.             Earc1
  1636.  
  1637.        
  1638.  
  1639.        9.1.3  FillCircle
  1640.  
  1641.                FillCircle(center_x, center_y, radius);
  1642.                int center_x, center_y, radius;
  1643.  
  1644.        RETURN VALUE
  1645.             none
  1646.  
  1647.        DESCRIPTION
  1648.  
  1649.             This function is same as Circle except that the circle drawn
  1650.        will be filled.
  1651.             
  1652.        EXAMPLE
  1653.  
  1654.                FillCircle(100,100,20);
  1655.  
  1656.  
  1657.                                      - 22 -
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.        GRAD User's Manual                                    June 7, 1987
  1664.  
  1665.             Assume the window is larger than  the circle.  Then the left
  1666.        most,  right most,  top and bottom points  of the  circle will be
  1667.        (80,100), (120,100), (100,80) and (100,120) respectively.
  1668.  
  1669.        FUNCTIONS INCLUDED
  1670.             FillEllipse, HorzLine, VertLine
  1671.  
  1672.        
  1673.        9.1.4  FillEllipse
  1674.  
  1675.                FillEllipse(center_x, center_y, horiz_axis, vert_axis);
  1676.                int center_x, center_y, horiz_axis, vert_axis;
  1677.  
  1678.        RETURN VALUE
  1679.             none
  1680.  
  1681.        DESCRIPTION
  1682.  
  1683.             This function is same as Ellipse except that the output will
  1684.        be an filled ellipse.
  1685.             
  1686.        EXAMPLE
  1687.  
  1688.                FillEllipse(100,100,40,20);
  1689.  
  1690.        FUNCTIONS INCLUDED
  1691.                FillCircle, HorzLine, VertLine
  1692.  
  1693.        
  1694.  
  1695.        9.1.5  Arc1
  1696.  
  1697.                Arc1(center_x, center_y, radius, arc_spec);
  1698.                int center_x, center_y, radius, arc_spec;
  1699.  
  1700.        RETURN VALUE
  1701.             none
  1702.  
  1703.        DESCRIPTION
  1704.  
  1705.             In the function Arc1, a circle is divided into 8 equal parts
  1706.        as defined later.  You may select any part or parts of the circle
  1707.        to  draw. Moreover, the arcs drawn are affected by the line style
  1708.        selected. 
  1709.             
  1710.             8   equal  parts  of  the  circle  is  obtained  by  drawing
  1711.        horizontal,  vertical and 2  diagonal lines (slope  is  1 and -1)
  1712.        through the center of the circle.  You specify which part  of the
  1713.        circle is required in the parameter arc_spec.
  1714.             
  1715.             The name  of  the eight parts  are  defined  as  follows (in
  1716.        clockwise direction):
  1717.          
  1718.          UP_RIGHT, RIGHT_UP, RIGHT_DOWN, DOWN_RIGHT, DOWN_LEFT,
  1719.          LEFT_DOWN, LEFT_UP and UP_LEFT.
  1720.  
  1721.        Additional constants defined include:
  1722.          UPPER_HALF    = RIGHT_UP | UP_RIGHT | UP_LEFT | LEFT_UP
  1723.  
  1724.                                      - 23 -
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.        GRAD User's Manual                                    June 7, 1987
  1731.  
  1732.          LOWER_HALF    = LEFT_DOWN | DOWN_LEFT | DOWN_RIGHT | RIGHT_DOWN
  1733.          LEFT_HALF     = UP_LEFT | LEFT_UP | LEFT_DOWN | DOWN_LEFT
  1734.          RIGHT_HALF    = DOWN_RIGHT | RIGHT_DOWN | RIGHT_UP | UP_RIGHT
  1735.          
  1736.             These constants can be found in the header file GRADARC.H
  1737.             
  1738.             As mentioned above,  the arc drawn is  affected  by the plot
  1739.        style selected.  Due to the way a circle  is drawn,  the style of
  1740.        the arc may not be  uniform.  The result  would be  better if the
  1741.        style setting is symmetrical.  (i.e. the bits when read from left
  1742.        to right or right to left are the same)
  1743.  
  1744.        EXAMPLES
  1745.        (1)     Arc1(50,50,30,UPPER_HALF);
  1746.        (2)     SetStyle(0xc3c3);
  1747.                Arc1(100,100,30,UPPER_HALF | LOWER_HALF);
  1748.  
  1749.             First example will draw the upper half  of  the circle only.
  1750.        The   second  example  will   draw  the  whole  circle   but  the
  1751.        circumference is drawn in dotted line style.
  1752.  
  1753.        FUNCTIONS INCLUDED
  1754.             Circle
  1755.  
  1756.        
  1757.        9.1.6  Earc1
  1758.  
  1759.                Earc1(center_x, center_y, horiz_axis, vert_axis,
  1760.                        arc_spec);
  1761.                int center_x, center_y, horiz_axis, vert_axis, arc_spec;
  1762.  
  1763.        RETURN VALUE
  1764.             none
  1765.  
  1766.        DESCRIPTION
  1767.             Earc1  is  very   similar to Arc1.  Earc1  draws a arc of an
  1768.        ellipse instead of  a arc  of  a  circle.  The  ellipse  is still
  1769.        divided into 8 region. The four lines to divide the ellipse are a
  1770.        horizontal line, a vertical line and two lines joining the points
  1771.        which slope of  the tangent is  1  and -1 respectively. Each line
  1772.        must  go  through the center.  If you do  not understand  how the
  1773.        ellipse is divided, just try some experiments.
  1774.             
  1775.             The naming of each  part is exactly the same  as  Arc1. They
  1776.        are:
  1777.          UP_RIGHT, RIGHT_UP, RIGHT_DOWN, DOWN_RIGHT, DOWN_LEFT,
  1778.          LEFT_DOWN, LEFT_UP and UP_LEFT.
  1779.  
  1780.        Additional constants defined include:
  1781.          UPPER_HALF    = RIGHT_UP | UP_RIGHT | UP_LEFT | LEFT_UP
  1782.          LOWER_HALF    = LEFT_DOWN | DOWN_LEFT | DOWN_RIGHT | RIGHT_DOWN
  1783.          LEFT_HALF     = UP_LEFT | LEFT_UP | LEFT_DOWN | DOWN_LEFT
  1784.          RIGHT_HALF    = DOWN_RIGHT | RIGHT_DOWN | RIGHT_UP | UP_RIGHT
  1785.          
  1786.             These constants can be found in the header file GRADARC.H
  1787.             
  1788.  
  1789.  
  1790.  
  1791.                                      - 24 -
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.        GRAD User's Manual                                    June 7, 1987
  1798.  
  1799.             The arcs drawn are affected by the plot style  selected. Due
  1800.        to the way an ellipse is drawn,  the style of the arc  may not be
  1801.        uniform.  The  result  would be  better  if the  style setting is
  1802.        symmetrical. (i.e. the bits when read from left to right or right
  1803.        to left are the same)
  1804.  
  1805.        EXAMPLES
  1806.        (1)     Earc1(50,50,30,60,UPPER_HALF);
  1807.        (2)     SetStyle(0xc3c3);
  1808.                Earc1(100,100,30,60,UPPER_HALF | LOWER_HALF);
  1809.  
  1810.             First example will draw the upper half of  the ellipse only.
  1811.        The  second  example  will   draw  the  whole  ellipse   but  the
  1812.        circumference is drawn in dotted line style.
  1813.             
  1814.        FUNCTIONS INCLUDED
  1815.             Ellipse
  1816.  
  1817.        
  1818.  
  1819.        9.1.7  Arc2
  1820.  
  1821.                Arc2(center_x, center_y, radius,
  1822.                         start_degree, degrees);
  1823.                int center_x, center_y, radius, start_degree, degrees;
  1824.  
  1825.        RETURN VALUE
  1826.             none
  1827.             
  1828.        DESCRIPTION
  1829.  
  1830.             This function draws a circular arc.  The angle of the arc is
  1831.        specified  in  terms of  degrees.  In order words,  the circle is
  1832.        divided  into 360  equal divisions.  You specify the starting and
  1833.        ending division to be drawn.
  1834.             
  1835.             The parameter  start_degree  can  be  any  value  within the
  1836.        allowable range of an integer.  Arc2 will take the positive value
  1837.        of start_degree mod 360 ( start_degree % 360 ).
  1838.             
  1839.             The parameter degrees can be  any values too.  However if it
  1840.        is larger than 360, it is set to 360. If it is less than or equal
  1841.        to zero, nothing will be drawn.
  1842.             
  1843.             The vertically  upward  direction is  considered  to  be the
  1844.        reference line. start_degree is the angle of the line joining the
  1845.        starting point of  the arc  and  center  and  the  reference line
  1846.        measured in clockwise direction. degrees is the angle between the
  1847.        lines joining the starting and ending points to the center.
  1848.             
  1849.             Immediately  after  execution  of  Arc2,  you  can  get  the
  1850.        coordinates  of  the starting  and  ending  points  by  using the
  1851.        function ArcPoint. See the description later in this chapter.
  1852.             
  1853.        EXAMPLES
  1854.        (1)     Arc2(100,100,50,270,180);
  1855.        (2)     Arc2(200,100,50,90,180);
  1856.  
  1857.  
  1858.                                      - 25 -
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.        GRAD User's Manual                                    June 7, 1987
  1865.  
  1866.             Example 1  draws the upper half of a circle. Example 2 draws
  1867.        the lower half of a circle.
  1868.             
  1869.        FUNCTIONS INCLUDED
  1870.             Arc1, Circle
  1871.  
  1872.        
  1873.  
  1874.        9.1.8  Earc2
  1875.  
  1876.                Earc2(center_x, center_y, horiz_axis, vert_axis,
  1877.                        start_degree, degrees);
  1878.                int center_x, center_y, horiz_axis, vert_axis;
  1879.                int start_degree, degrees;
  1880.  
  1881.        RETURN VALUE
  1882.             none
  1883.  
  1884.        DESCRIPTION
  1885.             Earc2  is  very  similar to  Arc2.  It draws elliptical arcs
  1886.        instead of  circular  arc.  The angle of the arc  is specified in
  1887.        terms of degrees. In order words, the ellipse is divided into 360
  1888.        divisions.  (note I do not  say equal division.)  You specify the
  1889.        starting and ending division to be drawn.
  1890.             
  1891.             The parameter  start_degree  can  be  any  value  within the
  1892.        allowable range of an integer.  Arc2 will take the positive value
  1893.        of start_degree mod 360 ( start_degree % 360 ).
  1894.             
  1895.             The parameter degrees can be  any values too.  However if it
  1896.        is larger than 360, it is set to 360. If it is less than or equal
  1897.        to zero, nothing will be drawn.
  1898.             
  1899.             The  vertically  upward  direction is  considered  to be the
  1900.        reference line.  Due to the limitation of the algorithm used, all
  1901.        angles are measured on a  output device with  aspect ratio (width
  1902.        of a pixel : height of a pixel) equal to vert_axis/horiz_axis. In
  1903.        other words, the ellipse appear as a `circle'.
  1904.             
  1905.             start_degree is the angle of  the line  joining the starting
  1906.        point of the arc and center  and the reference  line  measured in
  1907.        clockwise  direction.  degrees is  the  angle  between  the lines
  1908.        joining the starting and ending points to the center.
  1909.             
  1910.             Immediately  after  execution  of  Earc2,  you  can  get the
  1911.        coordinates  of  the starting  and  ending  points  by  using the
  1912.        function ArcPoint. See the description later in this chapter.
  1913.             
  1914.        EXAMPLES
  1915.        (1)     Earc2(100,100,60,30,270,180);
  1916.        (2)     Earc2(200,200,60,30,90,180);
  1917.  
  1918.             First  example draws the upper half  of  an  ellipse. Second
  1919.        example draws the lower half of an ellipse.
  1920.             
  1921.        FUNCTIONS INCLUDED
  1922.             Ellipse, Earc1
  1923.  
  1924.  
  1925.                                      - 26 -
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.        GRAD User's Manual                                    June 7, 1987
  1932.  
  1933.        9.1.9  ArcPoint
  1934.  
  1935.                ArcPoint(start_x, start_y, end_x, end_y);
  1936.                int *start_x, *start_y, *end_x, *end_y;
  1937.  
  1938.        RETURN VALUE
  1939.             none
  1940.             
  1941.        DESCRIPTION
  1942.             Using this function is only meaningful immediately after the
  1943.        execution of Arc2  or Earc2. If these are any other GRAD function
  1944.        calls in between, the values return may be incorrect.
  1945.             
  1946.             The return values are  stored in the four  parameters given.
  1947.        They  are the (logical)  coordinates  of the  starting and ending
  1948.        points  of  the arc just  drawn  without  considering  the window
  1949.        setting. That means if part of the arc is outside the window, the
  1950.        values  returned  is exactly the  same when the window  is larger
  1951.        than the arc.
  1952.             
  1953.        EXAMPLE
  1954.                Arc1(100,100,50,10,30);
  1955.                ArcPoint(&sx, &sy, &ex, &ey);
  1956.                Line(sx, sy, 100, 100); /* join the starting and ending
  1957.                Line(ex, ey, 100, 100);    point to the center         */
  1958.  
  1959.             A sector is drawn.
  1960.  
  1961.        FUNCTIONS INCLUDED
  1962.             none
  1963.  
  1964.        
  1965.        9.2  Hints
  1966.  
  1967.             Circle,  Arc1  and Arc2  are special cases of Ellipse, Earc1
  1968.        and Earc2.  They are provided because drawing circles are several
  1969.        times faster than drawing ellipse. If in one of your program, you
  1970.        use ellipse  most of the time  and only  requires drawing circles
  1971.        several times,  then you may use ellipse to  draw circles instead
  1972.        in order to reduce program size.
  1973.             
  1974.             Similarly,  Arc1  and Earc1  work faster than Arc2 and Earc2
  1975.        respectively. Use Arc1 and Earc1 whenever possible.
  1976.             
  1977.             ArcPoint is used with Arc2 and Earc2 only. It cannot be used
  1978.        with Arc1 and Earc1.
  1979.             
  1980.             Besides using Arc1,  Arc2, Earc1 and Earc2 to draw arcs, you
  1981.        can also use Circle and Ellipse to draw arcs. The technique is to
  1982.        define a window less than the complete circle or ellipse. So only
  1983.        part of the circle or ellipse is visible. This is useful when you
  1984.        do not need to draw an arc of exactly how many degrees. 
  1985.             
  1986.             Sometimes,  you may want  to draw a circle  or  a sector and
  1987.        then divided that into several smaller sector.  You may draw each
  1988.        small sectors individually but a better techniques is to draw the
  1989.        largest sector after combining the small ones then draw  lines to
  1990.        divided that.  In order to find the points on  the circumference,
  1991.  
  1992.                                      - 27 -
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.        GRAD User's Manual                                    June 7, 1987
  1999.  
  2000.        you  should first  define the window equal to  the center  of the
  2001.        circle (or ellipse).  Since  the window  only  include the center
  2002.        point,  the arc is not actually drawn  but the end points  of the
  2003.        arc are stilled calculated. See the example in GRADEGS.GCM.
  2004.             
  2005.             When you want to  know the end  points of a arc  but without
  2006.        actually drawing it out,  you must not define  the window outside
  2007.        the circle because Circle is clever enough not to draw it  but it
  2008.        is not clever to skip the drawing if the window  is  equal to the
  2009.        center point.
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059.                                      - 28 -
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.        GRAD User's Manual                                    June 7, 1987
  2066.  
  2067.        10  4-connected Region Filling
  2068.  
  2069.             Region  filling  functions  are  very  useful  and powerful.
  2070.        However, you must be very careful when using them because if your
  2071.        area you wished  to  fill is not enclosed  by  a proper boundary,
  2072.        then the `paint' will leaks out may make your frame very `dirty'.
  2073.             
  2074.             The region filling functions in GRAD will fill a 4-connected
  2075.        region. The definition of a 4-connected region is:
  2076.             
  2077.             All pixels in a 4-connected region  can be  reached one from
  2078.             the other by a sequence of any of the four  one-pixel moves:
  2079.             up,   down,  left,  right,  without  crossing  any  boundary
  2080.             pixel(s).
  2081.             
  2082.        A boundary pixel is defined by its state (either  set  or reset).
  2083.        The state for boundary pixels depends  on the plot type  using at
  2084.        that  time.   It  will  be  explained  later  in   the  functions
  2085.        description.
  2086.  
  2087.             To  fill  a  4-connected  region,   you  need  to  give  the
  2088.        coordinates of  any one  point  in  the  region,  regions filling
  2089.        functions will look for every pixels in the region by themselves.
  2090.        Using any point in  the region  as the starting point  would give
  2091.        the same  result.  (Remark:  but the speed of filling may  have a
  2092.        slight  difference.  Furthermore,  in  current  implementation of
  2093.        PatternFill,  this statement is not completely  true.  It will be
  2094.        explained later when the function is described.)
  2095.             
  2096.             All pixels  outside the window  defined are consider  in the
  2097.        state  same  as the boundary pixels.  In other words,  no `paint'
  2098.        will be painted outside the window.  That means when you may fill
  2099.        a completely  blank frame to a pattern you  want  because maximum
  2100.        window size is the frame size.
  2101.             
  2102.             I try  to give a precise description of  what  the functions
  2103.        will do and will not do in  different situation.  However most of
  2104.        them are common sense.  If you have any problem  in understanding
  2105.        what I said above, try to do some experiments and them come back.
  2106.             
  2107.             The functions that will be described in this chapter are:
  2108.                SolidFill       Set all pixels in the region to the
  2109.                                same state.
  2110.                PatternFill     Fill the region with a user specified
  2111.                                pattern.
  2112.  
  2113.        
  2114.        10.1  Functions Description
  2115.  
  2116.        10.1.1  SolidFill
  2117.  
  2118.                SolidFill(x,y);
  2119.                int x,y;
  2120.  
  2121.        RETURN VALUE
  2122.             none
  2123.             
  2124.        DESCRIPTION
  2125.  
  2126.                                      - 29 -
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.        GRAD User's Manual                                    June 7, 1987
  2133.  
  2134.             SolidFill  will  set all pixels  in  the  4-connected region
  2135.        containing (x,y) to the same state. The state depends on the plot
  2136.        type selected at that time.  The boundary pixel state is the same
  2137.        as the state used for filling.  If plot type is 0  (OR type), the
  2138.        region will be set to set state.  If  plot type is  1 (AND type),
  2139.        the region  will be set to  reset state.  If plot type  is 2 (XOR
  2140.        type),  the state used  will depend on  the initial state  of the
  2141.        starting point (x,y).  If it is reset, the region will set to set
  2142.        state, otherwise the region will set to reset state.
  2143.             
  2144.             SolidFill requires  temporary  storage  from  the  stack for
  2145.        working  memory.  The  amount  of memory required  depends on the
  2146.        complexity of  the region.  If you see  the  message  saying that
  2147.        insufficient working memory for filling,  you should increase the
  2148.        stack  size  and try again.  (Look at  your  C compiler reference
  2149.        manual to  see how to  increase  the  stack  size.)  You  are not
  2150.        required to  purposely increase  the stack size  whenever you use
  2151.        fill functions because working storage of 40 bytes are sufficient
  2152.        for most situation.  (Default stack size in most C compiler is at
  2153.        least 2K bytes.)
  2154.             
  2155.        EXAMPLES
  2156.        (1)     PlotType(0);
  2157.                Arc2(100,100,45,150);
  2158.                ArcPoint(&x1, &y1, &x2, &y2);
  2159.                Line(x1,y1,100,100);
  2160.                Line(x2,y2,100,100);
  2161.                SolidFill(100,100);
  2162.        (2)     /* Assume the frame is completely blank at this time */
  2163.                PlotType(2);
  2164.                Circle(100,100,50);
  2165.                SolidFill(100,100);
  2166.                SolidFill(100,100);
  2167.  
  2168.             In the first example,  a sector of 150  degree is filled. In
  2169.        the second  example,  you will  see the  circle  filled  and then
  2170.        erased. Read the description above for explanation.
  2171.             
  2172.        FUNCTIONS INCLUDE
  2173.             PatternFill
  2174.  
  2175.        
  2176.        10.1.2  PatternFill
  2177.  
  2178.                PatternFill(x,y,patptr,0);
  2179.                int x,y,*patptr;
  2180.  
  2181.        RETURN VALUE
  2182.             none
  2183.             
  2184.        DESCRIPTION
  2185.             PatternFill is  very  similar to  SolidFill  except  that it
  2186.        fills  the region  in  user  specified  pattern  and  it  has one
  2187.        limitation in current implementation.
  2188.             
  2189.  
  2190.  
  2191.  
  2192.  
  2193.                                      - 30 -
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.        GRAD User's Manual                                    June 7, 1987
  2200.  
  2201.             patptr is a pointer pointing to a integer array of  size 16.
  2202.        The lower order 8 bit will be displayed on the left of the higher
  2203.        order 8  bit.  So you have to swap the lower and  higher  byte in
  2204.        defining your  pattern.  There  is  no  restriction  on  what the
  2205.        pattern should look like. It can be completely set or reset.
  2206.             
  2207.             Owing to some  implementation problems,  the current version
  2208.        of  PatternFill can only  guarantee  filling  of  simple regions.
  2209.        Simple region means the region within the outer boundary does not
  2210.        contain  any  pixel(s)   in  the  same  state  as  the  boundary.
  2211.        Otherwise,  part of the region may not be filled.
  2212.             
  2213.             The actual operation of PatternFill is like  this: The front
  2214.        line  of filling  after the first line  is drawn  will not change
  2215.        direction.  It will continue goes up or down.  Therefore, in some
  2216.        cases,  it can fill area other than simple region. For example, a
  2217.        small rectangle inside a much larger  one and the  starting point
  2218.        is  either  above or below  the small rectangle inside  the large
  2219.        rectangle,  then the whole region will be filled. If the starting
  2220.        point is at the right of the  small rectangle,  the region on the
  2221.        left of the small rectangle will not be filled.
  2222.             
  2223.             Although PatternFill is  not  a  complete  implementation of
  2224.        4-connected region  filling function,  it is  sufficient for most
  2225.        application such as filling pie charts, bar charts etc.
  2226.             
  2227.             The fourth parameter is  not used  in current implementation
  2228.        but it  must be set to  0  in order to be compatible  with future
  2229.        version of PatternFill.
  2230.  
  2231.        EXAMPLE
  2232.                static int pattern[16]={
  2233.                    0x1111, 0x2222, 0x4444, 0x8888,
  2234.                    0x1111, 0x2222, 0x4444, 0x8888,
  2235.                    0x1111, 0x2222, 0x4444, 0x8888,
  2236.                    0x1111, 0x2222, 0x4444, 0x8888 };
  2237.                PlotType(0);
  2238.                Box(100,100,10,50,2,2);
  2239.                PatternFill(105,105,pattern,0);
  2240.  
  2241.             The Box drawn in  the example  will  be  filled  with shaded
  2242.        lines.
  2243.             
  2244.        FUNCTIONS INCLUDED
  2245.             SolidFill
  2246.             
  2247.  
  2248.        
  2249.        10.2  Hints
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.                                      - 31 -
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.        GRAD User's Manual                                    June 7, 1987
  2267.  
  2268.        11  Text Characters Related Functions
  2269.  
  2270.             A character in GRAD can be completely blank or a block up to
  2271.        about   120   by  120   pixels(can   be   change   easily  during
  2272.        re-comilation).   Font  files  are  loaded  into   memory  during
  2273.        execution time so that you can access  to different  type of font
  2274.        easily.
  2275.             
  2276.             Currently, two types of font files are supported. First type
  2277.        is fixed size font.  Every character in the file  occupy the same
  2278.        space. The second type is variable size font. Some people call it
  2279.        proportional  spacing characters.  The  type of the font  file is
  2280.        transparent to the user except  in some situation when  the exact
  2281.        size and position of  a character or  a string  of characters are
  2282.        important,  then you may need to know whether it is fixed size or
  2283.        variable size. More on this later in this chapter.
  2284.             
  2285.             The functions that will be described in this chapter are:
  2286.                LoadFont    Load a font file into memory.
  2287.                SelectFont  Select the active font type.
  2288.                RemvFont    Remove the font from memory.
  2289.                WriteStr    Write a string of character using the current
  2290.                            font selected.
  2291.                ReadStr     Read a string from keyboard
  2292.                NextXY      get the next coordinates for WriteStr or
  2293.                            ReadStr
  2294.  
  2295.        
  2296.        11.1  Functions Description
  2297.  
  2298.        11.1.1  LoadFont
  2299.  
  2300.                font_number=LoadFont(fontfilename);
  2301.                int font_number;
  2302.                char *fontfilename;
  2303.  
  2304.        RETURN VALUE
  2305.             A font number
  2306.  
  2307.        DESCRIPTION
  2308.             fontfilename is a DOS file name.  When LoadFont is executed,
  2309.        the  whole font file will  be loaded into  memory.  It is kept in
  2310.        memory until it  is  removed by  the  function  call  RemvFont or
  2311.        termination  of  GRAD.  When error occurs,  font number 0 will be
  2312.        returned.  You may  test  for  zero  to  perform  your  own error
  2313.        processing. See also SelectFont.
  2314.  
  2315.        POSSIBLE ERROR CONDITION
  2316.        a. Insufficient Memory
  2317.           font number zero will be returned
  2318.           
  2319.        b. Too Many Fonts Loaded
  2320.           The maximum number of fonts allowed to exist simultaneously is
  2321.           a system parameter.  If the number is exceed, font number zero
  2322.           will be returned.
  2323.           
  2324.        c. File Not File
  2325.  
  2326.  
  2327.                                      - 32 -
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.        GRAD User's Manual                                    June 7, 1987
  2334.  
  2335.           The  specified  DOS  file  is  not  found.  Font  number  0 is
  2336.           returned.
  2337.           
  2338.        EXAMPLE
  2339.                font1=LoadFont("E9X14.FON");
  2340.  
  2341.        FUNCTIONS INCLUDED
  2342.             RemvFont
  2343.  
  2344.        
  2345.        11.1.2  SelectFont
  2346.  
  2347.                ret=SelectFont(font_number);
  2348.                int ret, font_number;
  2349.  
  2350.        RETURN VALUE
  2351.             If -1  is returned,  it means the font number given does not
  2352.        exist or the font number is not assigned  to  any font. Otherwise
  2353.        the original font number will be returned.
  2354.  
  2355.        DESCRIPTION
  2356.             It selects the current  active font number.  The font number
  2357.        is obtained  from the  function LoadFont except  font number zero
  2358.        which is predefined as the font in BIOS.  It contains pattern for
  2359.        ASCII character 0  to character 127. It is the default font and a
  2360.        permanent font (means always available) in GRAD.
  2361.  
  2362.        EXAMPLE
  2363.                if ((old_font=SelectFont(font_number)) == (-1))
  2364.                        printf("Font %d does not exist\n",font_number);
  2365.                  .   .   .
  2366.                  .   .   .  use font_number as current font
  2367.                  .   .   .
  2368.                SelectFont(old_font);  /* return to original font */
  2369.  
  2370.        FUNCTIONS INCLUDED
  2371.             SelectFrame
  2372.  
  2373.        
  2374.        11.1.3  RemvFont
  2375.  
  2376.                ret=RemvFont(font_number);
  2377.                int ret, font_number;
  2378.  
  2379.        RETURN VALUE
  2380.             A return  value of  0  means  successful.  -1 means the font
  2381.        number does not exist or the font  number is not assigned  to any
  2382.        font.
  2383.  
  2384.        DESCRIPTION
  2385.             It removes the font from  GRAD and the  memory occupied will
  2386.        be deallocated.
  2387.             
  2388.        EXAMPLE
  2389.                if (RemvFont(font_number)==(-1))
  2390.                        printf("Font %d does not exist\n",font_number);
  2391.  
  2392.        FUNCTIONS INCLUDED
  2393.  
  2394.                                      - 33 -
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.        GRAD User's Manual                                    June 7, 1987
  2401.  
  2402.             LoadFont
  2403.  
  2404.        
  2405.        11.1.4  WriteStr
  2406.  
  2407.                WriteStr(options, direction, x, y, string, x_off, y_off);
  2408.                int options, direction, x, y, x_off, y_off;
  2409.                char *string;
  2410.  
  2411.        RETURN VALUE
  2412.             none
  2413.  
  2414.        DESCRIPTION
  2415.             WriteStr is the  most complicated function provided  in GRAD
  2416.        but it is not difficult to use once you understand it. Firstly, I
  2417.        will describe some basic concepts.
  2418.             
  2419.             Each character  in GRAD may be  different size  but they all
  2420.        considered to  be  a rectangular  box,  we called  it a character
  2421.        cell. Size of a character cell is the same for every character in
  2422.        the  fixed size  font file.  But they may be different  for every
  2423.        character in variable size font file.  The width of the character
  2424.        cell  is  called  cell  width and the height  is  called the cell
  2425.        height.  They are parameters  in  the font  file.  Sometimes, the
  2426.        character pattern may be larger  than the character  cell in some
  2427.        special cases but that will be ignored in the time being.
  2428.             
  2429.             There are a total of  seven  parameters  for  WriteStr. They
  2430.        will be described one by one below.  The constants are defined in
  2431.        the include file "GRADIO.H"
  2432.  
  2433.        a. direction  is only  meaningful when AUTO_MOVE options  is used
  2434.           (described  below).  It controls  the direction of  the string
  2435.           printed. Available selections are:
  2436.           LEFT         [default], move left after each character
  2437.           DOWN_LEFT    moves down and left after each character
  2438.           DOWN         moves down after each character
  2439.           DOWN_RIGHT   moves down and right after each character
  2440.           RIGHT        moves right after each character
  2441.           UP_RIGHT     moves up and right after each character
  2442.           UP           moves up after each character
  2443.           UP_LEFT      moves up and left after each character
  2444.           
  2445.        b. options  are divided into 4 sets. They control the referencing
  2446.           point  of  a  character  cell,  clearing  of  character  cell,
  2447.           operation  mode  and  movement  of  text   pointer.  Only  one
  2448.           selection from  each  set can be  used  at  a time. Selections
  2449.           from  different set should  be  combined  using  the  OR ( | )
  2450.           operator. Each set of options will be described separately.
  2451.           
  2452.           A. Referencing  point  options  tells  the  given  point (x,y)
  2453.              located in a character cell. Available selection are:
  2454.              BOTTOM_LEFT   is the default and it  is  most suitable when
  2455.                            direction LEFT is used.
  2456.              BOTTOM_CENTER is most suitable when direction UP or DOWN is
  2457.                            selected.
  2458.              BOTTOM_RIGHT  is  most  suitable  when   direction   UP  is
  2459.                            selected.
  2460.  
  2461.                                      - 34 -
  2462.  
  2463.  
  2464.  
  2465.  
  2466.  
  2467.        GRAD User's Manual                                    June 7, 1987
  2468.  
  2469.              TOP_LEFT      is  most  suitable  when  direction  DOWN  is
  2470.                            selected.
  2471.              TOP_CENTER    is most suitable when direction UP or DOWN is
  2472.                            selected.
  2473.              TOP_RIGHT     is  most  suitable  when  direction  RIGHT is
  2474.                            selected.
  2475.              LEFT_CENTER   is most suitable when direction LEFT or RIGHT
  2476.                            is selected.
  2477.              RIGHT_CENTER  is most suitable when direction LEFT or RIGHT
  2478.                            is selected.
  2479.              
  2480.           B. Clearing  of  Character  Cells.  Although  the  options are
  2481.              provided,  you are not encourage to  use it  and you should
  2482.              avoid  using it  whenever possible.  There are two reasons.
  2483.              First one is the side  effect problem.  Since characters in
  2484.              GRAD may have different sizes. Clearing of a character cell
  2485.              may leave part of  a larger character  under that character
  2486.              cell. Another reason is efficiency problem. If you want the
  2487.              characters  written on a  clear area,  you should clear the
  2488.              whole area  first and then  use  WriteStr  without clearing
  2489.              option. It will be much faster. However, in some situation,
  2490.              use of  this options  is unavoidable so they  are provided.
  2491.              Available selections are:
  2492.              NO_CLEAR      the default.  Do not clear the character cell
  2493.                            before writing.
  2494.              CLEAR_CELL    reset all  the  pixels  within  the character
  2495.                            cell.
  2496.              FILL_CELL     set all the pixels within the character cell.
  2497.              INVERSE_CELL  the effect of this option depends on the plot
  2498.                            type being used.  If plot type 0 is used, the
  2499.                            character cell will be cleared.  If plot type
  2500.                            1 is used, the character cell will be filled.
  2501.                            If  plot type 2  is used,  the character cell
  2502.                            will be inverted.
  2503.           
  2504.           C. Two operation mode is provided. They are:
  2505.              WRITE     the default.  Perform all operations specified in
  2506.                        the other options and then  write  the characters
  2507.                        to the frame.
  2508.              NO_WRITE  Perform  all other operations  specified in other
  2509.                        options but the characters are not written to the
  2510.                        frame.
  2511.              
  2512.           D. Text  pointer movement  options controls the  update of the
  2513.              pointer  after   each  character   is   written.  Available
  2514.              selections are:
  2515.              AUTO_MOVE the default. After writing of character, the text
  2516.                        pointer will be update according to the direction
  2517.                        and  the  cell  height  and  cell  width  of  the
  2518.                        character just written in addition  to the offset
  2519.                        value for x and  y  coordinate  specified  in the
  2520.                        function call.
  2521.              FIX_MOVE  ignore   direction   and   the   character   cell
  2522.                        information.  Update the text pointer  using only
  2523.                        the offset value specified.
  2524.              VAR_MOVE  Update the text pointer using the  user specified
  2525.                        function   in  addition  to   the   offset  value
  2526.                        specified.  This option allows the  user to place
  2527.  
  2528.                                      - 35 -
  2529.  
  2530.  
  2531.  
  2532.  
  2533.  
  2534.        GRAD User's Manual                                    June 7, 1987
  2535.  
  2536.                        the characters wherever he wants. The option will
  2537.                        be  described  in  full  in  the  section  "using
  2538.                        SPACING_FUNC" in the chapter "Advance Topics".
  2539.              
  2540.        c. x and y are the starting coordinates.
  2541.  
  2542.        d. string is a null terminated string which is  printed using the
  2543.           current active font.
  2544.  
  2545.        e. x_off and y_off are the offset  value which will  be  added to
  2546.           the text pointer after each character is written.
  2547.  
  2548.        EXAMPLES
  2549.        1.      WriteStr(0,0,10,100,"This is a test!",0,0);
  2550.        2.      WriteStr(0,0,10,200,"This is a test!",2,0);
  2551.        3.      PlotType(1);
  2552.                WriteStr(TOP_LEFT | SET_CELL,DOWN,10,300,
  2553.                                "This is a test!",0,0);
  2554.  
  2555.             The first example is  the  simplest  form.  It  uses default
  2556.        options.  The second example is the same as the  first one except
  2557.        the spacing between the characters are larger. 2 extra pixels  in
  2558.        the  horizontal  directions are  added to the  text pointer after
  2559.        each  character.  The third  example  will  write  the  string in
  2560.        reverse video from top to down.
  2561.             
  2562.        FUNCTIONS INCLUDED
  2563.             (writec)
  2564.  
  2565.        
  2566.        11.1.5  ReadStr
  2567.  
  2568.                ReadStr(buffer, max_len, startx, starty, mode,
  2569.                                 cursor, end_of_input);
  2570.                char *buffer;
  2571.                int max_len, startx, starty, mode, cursor, end_of_input;
  2572.                
  2573.        RETURN VALUE
  2574.             number of characters entered
  2575.             
  2576.        DESCRIPTION
  2577.             ReadStr reads a line of input from  the keyboard,  echo each
  2578.        character typed and put them into buffer.
  2579.  
  2580.        buffer    is  a character array where the  input  is  stored. The
  2581.                  string  is   null  terminated  and   no  other  control
  2582.                  characters will be stored.
  2583.  
  2584.        max_len   is  the  length  of  the  buffer.   Maximum  number  of
  2585.                  characters can be entered is max_len - 1.
  2586.  
  2587.        startx, starty is  the starting  coordinate  of  the baseline for
  2588.                  echoing the characters entered.
  2589.  
  2590.        mode      controls how the cursor will appear.
  2591.                  NO_CURSOR       no cursor is displayed but the area
  2592.                                  under the cursor is cleared
  2593.                  DISP_CURSOR     just display the cursor
  2594.  
  2595.                                      - 36 -
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.        GRAD User's Manual                                    June 7, 1987
  2602.  
  2603.                  BLINK_CURSOR    the cursor character turns on and off
  2604.                  REVERSE_CURSOR  it keeps reversing the cursor
  2605.                  
  2606.                  You may only use one of the above 4 options at a time
  2607.                  but it may combine with the next option.
  2608.                  SHOW_EOI        shows end of input character when
  2609.                                  return is pressed.
  2610.                                  
  2611.        cursor    the character used for cursor
  2612.  
  2613.        end_of_input the character displayed at the end of the line if
  2614.                  SHOW_EOI option is specified in mode.
  2615.  
  2616.             There are  two special key in  ReadStr.  The return key will
  2617.        terminate the input line  and the backspace key  will  delete the
  2618.        last  character typed on  the  line  if  any.  All  other control
  2619.        characters  are ignored.  If  more characters are input  than the
  2620.        buffer can hold, all excess characters will be discarded.
  2621.             
  2622.        EXAMPLE
  2623.                char line[80];
  2624.                ReadStr(line,80,0,100,BLINK_CURSOR | SHOW_EOI, 0x5f, 17);
  2625.  
  2626.             It reads input from  the keyboard  and put  them  into line.
  2627.        Maximum length is 79 characters plus a carriage return.
  2628.  
  2629.        FUNCTIONS INCLUDED
  2630.             writec, WriteStr, HorzLine, PlotType
  2631.  
  2632.        
  2633.        11.1.6  NextXY
  2634.  
  2635.                NextXY(x,y);
  2636.                int *x, *y;
  2637.  
  2638.        RETURN VALUE
  2639.             values  are   returned  in  the   2   parameters.  They  are
  2640.        coordinates for next character in ReadStr and WriteStr.
  2641.             
  2642.        DESCRIPTION
  2643.             NextXY is for ReadStr and WriteStr only. It returns the next
  2644.        coordinate  in  ReadStr  and  WriteStr  if  there   is  any  more
  2645.        characters to  display.  It  should  be  called immediately after
  2646.        ReadStr and WriteStr otherwise the result may be destroyed.
  2647.  
  2648.        EXAMPLE
  2649.                WriteStr(0,0,10,100,"Enter your name : ",0,0);
  2650.                NextXY(&x, &y);
  2651.                ReadStr(line,80,x,y,BLINK_CURSOR,0x5f,0x5f);
  2652.  
  2653.             It print the string "Enter your name : " and then prompt for
  2654.        input immediate after the string.
  2655.  
  2656.        FUNCTIONS INCLUDED
  2657.                none
  2658.  
  2659.  
  2660.  
  2661.  
  2662.                                      - 37 -
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.        GRAD User's Manual                                    June 7, 1987
  2669.  
  2670.        12  Block Operations
  2671.  
  2672.             The functions provide ways  to move data  between frames and
  2673.        between frame and external data.  Each block must be a rectangle.
  2674.        When data are  moved to a  GRAD frame,  it can be OR,  AND or XOR
  2675.        with the original data according to the plot type setting.
  2676.             
  2677.             The functions that will be described in this chapter are:
  2678.                BlockCopy       Copy a block between 2 frames
  2679.                BlockSave       Move a block to a disk file
  2680.                BlockLoad       Load a block from a disk file
  2681.  
  2682.        
  2683.        12.1  Function Description
  2684.  
  2685.        12.1.1  BlockCopy
  2686.  
  2687.                ret=BlockCopy(src_frame, src_x, src_y,
  2688.                              dest_frame, dest_x, dest_y,
  2689.                              length, height);
  2690.                int ret, src_frame, src_x, src_y, dest_frame, dest_x;
  2691.                int dest_y, length, height;
  2692.  
  2693.        RETURN VALUE
  2694.             0 means OK. -1 means one of the frame specified is invalid.
  2695.             
  2696.        DESCRIPTION
  2697.  
  2698.             BlockCopy is  used  to  copy  a rectangular  block  from the
  2699.        source frame (src_frame)  to the  destination  frame (dest_frame)
  2700.        specified.  The two frame number can be the same or different but
  2701.        they must  exist at  the time  the call  is  made.  If  the frame
  2702.        numbers are the same,  the source block and the destination block
  2703.        must  not  overlapped  with  each  other  otherwise unpredictable
  2704.        result may be obtained.
  2705.             
  2706.             In  the current implementation,  the  lower 4  bit of dest_x
  2707.        must be  equal to  lower 4  bit of src_x.  If not, BlockCopy will
  2708.        force them to  be equal  by copying the  lower 4  bit of src_x to
  2709.        dest_x.
  2710.             
  2711.             When the block is copied to the destination frame, the block
  2712.        will be OR,  AND or XOR with the original data in the destination
  2713.        block according to the current plot type selected.
  2714.             
  2715.             Both the window setting of the source  and destination frame
  2716.        will affect the size of the block actually copied. BlockCopy will
  2717.        not copy  any data  from  area  outside the window  of the source
  2718.        frame and it will not write to any area outside of  the window of
  2719.        the destination frame.
  2720.             
  2721.             BlockCopy will  not affect  the  current  frame  number. The
  2722.        source and destination frame may be  different  from  the current
  2723.        frame selected.
  2724.             
  2725.        EXAMPLE
  2726.  
  2727.                frame1=CreateFrame(960,480);
  2728.  
  2729.                                      - 38 -
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.        GRAD User's Manual                                    June 7, 1987
  2736.  
  2737.                frame2=SelectFrame(frame1);
  2738.                Ellipse(480,240,450,230);
  2739.                BlockCopy(frame1,0,0,frame2,0,0,960,480);
  2740.                
  2741.             Let's assume  the Color Graphics  Adapter display  memory is
  2742.        the original frame selected before execution of the example above
  2743.        and the window size is equal to  frame size.  frame2 will contain
  2744.        the  frame  number  of  the  CGA  frame.  The  length  and height
  2745.        specified in the BlockCopy command is  960  and 480 respectively.
  2746.        However,  the resolution of a CGA is only 640  and 200. Therefore
  2747.        only the upper left corner (640 by 200) of frame1 is copied.
  2748.             
  2749.        FUNCTIONS INCLUDED
  2750.             
  2751.             none
  2752.  
  2753.        
  2754.        12.1.2  BlockSave
  2755.  
  2756.                BlockSave(start_x, start_y, filename, width, height);
  2757.                int start_x, start_y, width, height;
  2758.                char *filename;
  2759.  
  2760.        RETURN VALUE
  2761.             none
  2762.  
  2763.        DESCRIPTION
  2764.             
  2765.             BlockSave will  save  the  block  specified  in  the current
  2766.        active frame to a file with the  given filename.  All data if any
  2767.        in that file will be replaced by the new data.  If that file does
  2768.        not exist, a new file will be created. The coordinates of the top
  2769.        left corner  of  the block is  given by start_x  and start_y. The
  2770.        width and height is specified in the corresponding parameter with
  2771.        the same name.  If the block does  not lay completely  inside the
  2772.        window, only the portion inside the window is saved. If the block
  2773.        is completely outside the window,  no data will be saved  and the
  2774.        file will not be affect if it already exist or the file  will not
  2775.        be created.
  2776.             
  2777.             The actual width and height of  the block will  be stored in
  2778.        the data file also.  The format of the data file is  described in
  2779.        the appendix.
  2780.  
  2781.        EXAMPLE
  2782.  
  2783.                BlockSave(0,0,"test.blk",100,100);
  2784.  
  2785.             Assume the whole block is inside the window,  then the block
  2786.        100 by 100 pixels will be stored in the file "test.blk".
  2787.  
  2788.        FUNCTIONS INCLUDED
  2789.             BlockLoad
  2790.  
  2791.        
  2792.        12.1.3  BlockLoad
  2793.  
  2794.                ret=BlockLoad(start_x, start_y, filename);
  2795.  
  2796.                                      - 39 -
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.        GRAD User's Manual                                    June 7, 1987
  2803.  
  2804.                int ret, start_x, start_y;
  2805.                char *filename;
  2806.  
  2807.        RETURN VALUE
  2808.             0  means success. -1 indicates error. It may due to file not
  2809.        found or bad file.
  2810.             
  2811.        DESCRIPTION
  2812.  
  2813.             BlockLoad is the counterpart of BlockSave.  It loads a block
  2814.        file into  the current frame with  the top  left  hand  corner at
  2815.        (start_x,  start_y).  In current implementation, the lower bit of
  2816.        start_x must be equal to the lower 4  bit of the original start_x
  2817.        (in BlockSave)  when  BlockSave is  used.  If not, BlockLoad will
  2818.        force them to match by changing the start_x of BlockLoad.
  2819.             
  2820.             The  way  the  data  is  stored  in  the  current  frame  is
  2821.        controlled by the current plot type. 
  2822.             
  2823.             This is  no  explicit command to load  part of a  block file
  2824.        only.  However,  you may do this by setting the window to exclude
  2825.        part of the block to  be loaded.  No data will  be loaded outside
  2826.        the current window setting.
  2827.             
  2828.        EXAMPLE
  2829.  
  2830.                BlockLoad(400,0,"test.blk");
  2831.  
  2832.        FUNCTIONS INCLUDED
  2833.             BlockSave
  2834.  
  2835.        
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846.  
  2847.  
  2848.  
  2849.  
  2850.  
  2851.  
  2852.  
  2853.  
  2854.  
  2855.  
  2856.  
  2857.  
  2858.  
  2859.  
  2860.  
  2861.  
  2862.  
  2863.                                      - 40 -
  2864.  
  2865.  
  2866.  
  2867.  
  2868.  
  2869.        GRAD User's Manual                                    June 7, 1987
  2870.  
  2871.        13  Frame Printing
  2872.  
  2873.             Before you try to print a frame using the function described
  2874.        in this chapter,  make sure that you have the  correct driver for
  2875.        your printer.  Customizing  of  printer  driver  is  discussed in
  2876.        Appendix A.
  2877.             
  2878.             Since  different   printers  may   use   different  ways  in
  2879.        controlling graphics printing and you may  have different printer
  2880.        driver,  it is impossible to discuss every possible cases. Hence,
  2881.        I would discuss the general situation and use EPSON FX printer as
  2882.        an example.  If you have problem in  understanding,  try to ask a
  2883.        friend who owns  a EPSON FX  or compatible printer to  explain to
  2884.        you.
  2885.             
  2886.             The function that will be explained in this chapter is:
  2887.             
  2888.             PrintFrame
  2889.                Dump the current selected frame to the printer any may
  2890.                overlay with text data.
  2891.  
  2892.             
  2893.             Allowing  the  merge  printing  of  text  and  graphics data
  2894.        greatly  increase  the  speed  of  printing  when  both  text and
  2895.        graphics data are required because  it don't need to  convert the
  2896.        text into graphics data before printing by the program.
  2897.             
  2898.             Use of software printer  spooler can speed up  the printing.
  2899.        Size of the buffer should be 16K bytes or more.
  2900.  
  2901.        
  2902.        13.1  Function Description
  2903.  
  2904.        13.1.1  PrintFrame
  2905.  
  2906.                PrintFrame(options, page, line, line_height, offset);
  2907.                int option, line, line_height, offset;
  2908.                char *page[];
  2909.  
  2910.        RETURN VALUE
  2911.             none
  2912.  
  2913.        DESCRIPTION
  2914.             This function merge print the text data given if any and the
  2915.        current active frame to the printer. The parameters are explained
  2916.        below. The constants can be found in GRADIO.h
  2917.             
  2918.        a. options  consist of  2  sets of  options  for  the  control of
  2919.           vertical  and horizontal  printing  density. Available options
  2920.           depends  on  the printer driver  you have.  The  options given
  2921.           below are for the EPSON FX printer driver.
  2922.           
  2923.           A. Vertical density
  2924.              NORMAL_DOT   The spacing between 2 vertical dot on paper
  2925.                           is equal to the spacing between 2 pins on the
  2926.                           print head in the printer.
  2927.              
  2928.              SMALL_DOT    The spacing between 2 vertical dot is 1/3 of
  2929.  
  2930.                                      - 41 -
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.        GRAD User's Manual                                    June 7, 1987
  2937.  
  2938.                           spacing between 2 pins on the print head.
  2939.              
  2940.              I think the best way to explain these is to see an example.
  2941.              The  EPSON FX  printers can print  up to 216  dots per inch
  2942.              vertically.  However, the spacing between pins in the print
  2943.              head is 1/72  inch (3 times of 1/216). In order to print at
  2944.              high  resolution,  the printer spaces 1/216  inch after the
  2945.              first pass  and the  second  pass  and  then  spaces 22/216
  2946.              inches (2/216  +  22/216  =  8/72) and repeat the procedure
  2947.              again.  As a result,  it can print 216  dots vertically per
  2948.              inch.
  2949.              
  2950.              When you specify the SMALL_DOT option, PrintFrame will take
  2951.              advantage of this features and the print the frame  at high
  2952.              resolution. Otherwise, the frame will be printed at 72 dots
  2953.              per inch vertically.
  2954.              
  2955.           B. Horizontal density
  2956.              LOW_DENSITY     The resolution is 60 dots per inch
  2957.              MEDLOW_DENSITY  The resolution is 72 dots per inch
  2958.              MEDIUM_DENSITY  The resolution is 80 dots per inch
  2959.              HIGH_DENSITY    The resolution is 120 dots per inch
  2960.              ULTRA_DENSITY   The resolution is 240 dots per inch
  2961.              
  2962.              Not all EPSON FX  printers  support all of  the above print
  2963.              mode. Read you manual to see which modes are supported.
  2964.              
  2965.        b. page is a pointer to an array of character pointer. PrintFrame
  2966.           gets the text  data using  this pointer.  Also see the example
  2967.           below.
  2968.  
  2969.        c. line is the number of line given in the array pointer by page.
  2970.           If it is zero,  PrintFrame will not look  at page  and no text
  2971.           data overlaid with the frame in printing.
  2972.  
  2973.        d. height  is the number of points between the base  lines of two
  2974.           rows of text data.  A point is defined as the distance between
  2975.           two pins on the print head. For example, the distance two pins
  2976.           on the print head  of  EPSON FX  printer is 1/72  inch. If you
  2977.           want to print at 6  lines per inch,  you should specify 12 (72
  2978.           divided by 6) as height.
  2979.  
  2980.        e. offset  specify  the distance of the first line  of  text data
  2981.           from  the top of  the frame.  offset  is  in term of  point as
  2982.           defined just a second ago. Negative offset means the text data
  2983.           is shifted downward relative to the top of the frame. Positive
  2984.           offset means the text data is shifted upward.
  2985.  
  2986.             
  2987.             The text data and the frame need not be the same  length and
  2988.        width.  However the text data must not longer than 1 line because
  2989.        that will cause auto line feed of the printer and  the  text data
  2990.        must not contain any control codes that will cause  the moving of
  2991.        paper.  There is an exceptional case when the printer is  in near
  2992.        letter quality mode, the printer will automatically line feed for
  2993.        1/216. This is OK.
  2994.             
  2995.        FUNCTIONS INCLUDED
  2996.  
  2997.                                      - 42 -
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.        GRAD User's Manual                                    June 7, 1987
  3004.  
  3005.             none
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.  
  3044.  
  3045.  
  3046.  
  3047.  
  3048.  
  3049.  
  3050.  
  3051.  
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057.  
  3058.  
  3059.  
  3060.  
  3061.  
  3062.  
  3063.  
  3064.                                      - 43 -
  3065.  
  3066.  
  3067.  
  3068.  
  3069.  
  3070.        GRAD User's Manual                                    June 7, 1987
  3071.  
  3072.        14  The DRAW function
  3073.  
  3074.             Draw function provides features similar turtle graphics. The
  3075.        main idea  is  to keep track  of the current coordinates  and use
  3076.        these  coordinate when a function  required  a coordinate number.
  3077.        This help the user to  draw complex figures  without worrying the
  3078.        exact coordinates.
  3079.             
  3080.             The command string for draw  function is very  compact. This
  3081.        also help keeping the program size small.  On the other hand, use
  3082.        of  Draw  functions  will  include  all  GRAD  functions  that is
  3083.        accessible  from Draw at link time even if  you do  not use them.
  3084.        This will increase the executable file size.
  3085.  
  3086.        
  3087.        14.1  Draw
  3088.  
  3089.                Draw(string, parm1, parm2);
  3090.                char *string;
  3091.                int parm1, parm2;
  3092.  
  3093.        RETURN VALUE
  3094.             none
  3095.             
  3096.        DESCRIPTION
  3097.             string is  the  Draw  command  string.  The  syntax  will be
  3098.        described later.  parm1  and parm2 will be assigned to X and Y of
  3099.        marker 0. It will be explained further when we talk about marker.
  3100.        The command string can be any length  but it  has to  be in ASCII
  3101.        and terminated by a NULL character.
  3102.             
  3103.             On entry,  the current environment is saved.  If there is no
  3104.        environment slot  available,  it  is  an  irrecoverable error and
  3105.        program will normally terminated unless a function  is registered
  3106.        for error handling.  On exit,  the  environment  is  not restored
  3107.        automatically.  However,  Draw  provides  an  environment restore
  3108.        command (EO).  You can use it at the end of the command string to
  3109.        restore the environment before exit.
  3110.             
  3111.             The syntax for the command string is given below.
  3112.                :=    stands for define as
  3113.                |     means or
  3114.                [  ]  means this is optional
  3115.                {  }  select one of the entities inside
  3116.          
  3117.          CMD_STRING := CMD_UNITS
  3118.          CMD_UNITS  := CMD_UNIT | CMD_UNIT CMD_UNITS
  3119.          CMD_UNIT   := CMD_CODE[$] [PARAMETERS]
  3120.          CMD_CODE   := LETTER LETTER
  3121.          PARAMETERS := PARAMETER | PARAMETER , PARAMETERS
  3122.          PARAMETER  := DECIMAL | HEXADECIMAL | {&|%}DIGIT{X|Y}
  3123.          DIGIT      := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  3124.          DECIMAL    := [+|-]DIGITS
  3125.          DIGITS     := DIGIT | DIGITDIGITS
  3126.          HEXDIGIT   := DIGIT | A | B | C | D | E | F | a | b | c | d
  3127.                            | e | f
  3128.          HEXADECIMAL:= 0XHEXDIGITS | 0xHEXDIGITS
  3129.          HEXDIGITS  := HEXDIGIT | HEXDIGITHEXDIGITS
  3130.  
  3131.                                      - 44 -
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.        GRAD User's Manual                                    June 7, 1987
  3138.  
  3139.          LETTER is defined as letter A to Z and a to z
  3140.          
  3141.        If there is  any space separating  any 2  entities  in  the above
  3142.        definition,  it means zero, one or spaces are allowed except when
  3143.        this  is  ambiguity.  For  example,  the  last  parameter  in the
  3144.        preceding CMD_UNIT is  a hexadecimal number.  Since a hexadecimal
  3145.        number may contain a to  f and A to  F which are  also  belong to
  3146.        LETTER.  Therefore it  is necessary  to insert a space  after the
  3147.        last parameter if  that  is  a hexadecimal  number  and  the next
  3148.        CMD_CODE begins with letter a to f or A to F.
  3149.  
  3150.             Below is  a  table  showing  the  command  codes,  number of
  3151.        parameters required,  whether the current coordinates is affected
  3152.        and  a brief description.  P#  (#  represent a digit from 1 to 9)
  3153.        stands for the parameter #.  For example P1  stands for the first
  3154.        parameter.
  3155.  
  3156.        CMD_  no. of  affect
  3157.        CODE  param.  coord.   Description
  3158.        ----  -----   ------   -----------
  3159.         RS     0       No     Reset the window to frame size, logical
  3160.                               origin to physical coordinate 0. The
  3161.                               current coordinates number will change to
  3162.                               reflect the change of the coordinate
  3163.                               system if necessary.
  3164.  
  3165.         LF     1       Yes    move left P1 pixels.
  3166.         RT     1       Yes    move right P1 pixels.
  3167.         UP     1       Yes    move up P1 pixels.
  3168.         DN     1       Yes    move down P1 pixels.
  3169.         UL     1       Yes    move up and left P1 pixels.
  3170.         UR     1       Yes    move up and right P1 pixels.
  3171.         DL     1       Yes    move down and left P1 pixels.
  3172.         DR     1       Yes    move down and right P1 pixels.
  3173.         JR     2       Yes    move left and down P1 and P2 pixels
  3174.                               respectively. P1 and P2 can be negative to
  3175.                               stands for moving right and up.
  3176.         JA     2       Yes    jump to (P1,P2)
  3177.         /* NW and PU only affects the commands */
  3178.         /* LF, RT, UP, DN, UL, UR, DL, DR, JR  */
  3179.                               above                                       
  3180.                               */
  3181.         WR     0       No     write (selects plot type OR)
  3182.         ER     0       No     erase (selects plot type AND)
  3183.         RV     0       No     reverse (selects plot type XOR)
  3184.         NW     0       No     set flag such that when the current
  3185.                               coordinate move, no ink is left on the
  3186.                               frame.
  3187.         PU     0       No     Pen Up for the during next command. The
  3188.                               effect is similar to NW except it only
  3189.                               last for 1 command only.
  3190.         HL     2       Yes    draws a horizontal line starting at
  3191.                               current coordinate and length P1 to the
  3192.                               left and width P2 downward. P1 and P2
  3193.                               cannot be negative.
  3194.  
  3195.  
  3196.  
  3197.  
  3198.                                      - 45 -
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.        GRAD User's Manual                                    June 7, 1987
  3205.  
  3206.         VL     2       Yes    draws a vertical line starting at current
  3207.                               coordinates and length P1 downward and
  3208.                               width P2 to the left. P1 and P2 cannot be
  3209.                               negative.
  3210.         SO     0              set the current position as the new
  3211.                               origin. Current coordinates are set to
  3212.                               zero to reflect change of coordinate
  3213.                               system.
  3214.         SY     1       No     set line style to P1
  3215.         AS     1       No     set arc drawing specification for use by
  3216.                               CI (circle) and EL (ellipse).
  3217.         MK     1       No     put current coordinates into marker P1.
  3218.         MK     3       No     put (P2,P3) into marker P1
  3219.         WN     2       No     the 2 corners of the window is the current
  3220.                               location and (P1,P2).
  3221.         DY     1       No     delay for P1/100 seconds. It is not very
  3222.                               accurate.
  3223.         CI     1       No     current coordinates are the center, P1 is
  3224.                               the radius. It also affected by the arc
  3225.                               specification setting.
  3226.         EL     2       No     current coordinates are the center, P1 is
  3227.                               the length of the horizontal axis and P2
  3228.                               is the length of the vertical axis.
  3229.         RE     2       No     draws a rectangle with upper left corner
  3230.                               at current location and width and height
  3231.                               are P1 and P2 respectively.
  3232.         BX     4       No     draws a box with upper left corner at
  3233.                               current location. Width and height are P1
  3234.                               and P2 respectively. P3 and P4 are the
  3235.                               width of the horizontal and vertical lines
  3236.                               of the box.
  3237.         FC     1       No     draws a solid circle with radius P1
  3238.         FE     2       No     draws a solid ellipse with horizontal and
  3239.                               vertical axes equal to P1 and P2
  3240.                               respectively.
  3241.         ES     0       No     environment variables save into the slot
  3242.                               allocated on entry.
  3243.         EO     1              environment restore from the slot using
  3244.                               parameter P1. KEEP_SLOT is implied. It
  3245.                               does not affect the value of current
  3246.                               coordinates but it may affect the location
  3247.                               of the origin and hence affect the actual
  3248.                               location.
  3249.         FI     0       No     Fill the region starting from current
  3250.                               location.
  3251.  
  3252.             Marker is a  unique feature provided by  draw so it  will be
  3253.        discussed in  detail.  Draw process a total of  10  markers. Each
  3254.        marker can store 2  integer values in the registers called  X and
  3255.        Y.  Coordinate numbers are usually  stored but you  may store any
  3256.        integer values in the marker.  Marker 0 is a special marker which
  3257.        initially values in registers X and Y are  the  second  and third
  3258.        parameters given when Draw is called.
  3259.             
  3260.             There are two ways to retrieve a marker. The first way is to
  3261.        retrieve the absolute value of the markers.  It is done by typing
  3262.        %#X or  %#Y (#  stands  for a digit 0..9)  in the  place  where a
  3263.        parameter is expected. The second way is to retrieve the value of
  3264.  
  3265.                                      - 46 -
  3266.  
  3267.  
  3268.  
  3269.  
  3270.  
  3271.        GRAD User's Manual                                    June 7, 1987
  3272.  
  3273.        the marker relative to the  current coordinates.  You can do this
  3274.        by typing &#X or &#Y in the place where a parameter  is expected.
  3275.        When the X part is retrieved,  the return value will  be relative
  3276.        to current X coordinate. Similarly when Y part is retrieved.
  3277.             
  3278.             In  the table given above,  some  functions  when  used will
  3279.        affect  the  current  coordinates.  However,  if  you  add  a '$'
  3280.        immediately after the command code,  then the current coordinates
  3281.        will not  be  affected.  Adding  a  '$'  is  only  meaningful for
  3282.        functions that is stated 'Yes' in the table above.
  3283.             
  3284.        EXAMPLE
  3285.                Draw("NW RT6 AS0xc0 EL5,9 UP9 WR RT228",0,0);
  3286.                Draw("NW DN9 AS0x03 EL5,9 RT5 WR DN304",0,0);
  3287.                Draw("NW LF6 AS0x0c EL5,9 DN9 WR LF228",0,0);
  3288.                Draw("NW UP9 AS0x30 EL5,9 LF5 WR UP304",0,0);
  3289.             
  3290.             The above lines will draw a rectangle with round corner.
  3291.             
  3292.        FUNCTIONS INCLUDED
  3293.             Line,  Plottype,  Dot, HorzLine, VertLine, SetStyle, SetOrg,
  3294.        RelOrg,   SetWin,   Circle,  Arc1,  Ellipse,  Earc1,  FillCircle,
  3295.        FillEllipse, EnvSave, EnvRsto, SolidFill, PatternFill.
  3296.  
  3297.  
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.  
  3307.  
  3308.  
  3309.  
  3310.  
  3311.  
  3312.  
  3313.  
  3314.  
  3315.  
  3316.  
  3317.  
  3318.  
  3319.  
  3320.  
  3321.  
  3322.  
  3323.  
  3324.  
  3325.  
  3326.  
  3327.  
  3328.  
  3329.  
  3330.  
  3331.  
  3332.                                      - 47 -
  3333.  
  3334.  
  3335.  
  3336.  
  3337.  
  3338.        GRAD User's Manual                                    June 7, 1987
  3339.  
  3340.        15  Miscellaneous Functions
  3341.  
  3342.             This chapter will describe  those functions that  do not fit
  3343.        into any other chapter in this manual. It includes:
  3344.                
  3345.                GRADinit        initialize the GRAD environment
  3346.                cleanup         clean up everything before exit
  3347.                XHLine          extend to left and right from a point
  3348.                writec          write a single character
  3349.  
  3350.        
  3351.        15.1  Functions Description
  3352.  
  3353.        15.1.1  GRADinit
  3354.  
  3355.                GRADinit();
  3356.  
  3357.        RETURN VALUE
  3358.             none
  3359.  
  3360.        DESCRIPTION
  3361.             GRADinit  initialize  the  GRAD  environment  and  test  the
  3362.        processor speed and put the  result  into  TEN_MS.  See  also the
  3363.        description of TEN_MS.  It should be called before using any GRAD
  3364.        functions.  Once GRADinit is called, you must call cleanup before
  3365.        exit. Read the description of cleanup in next section.
  3366.             
  3367.        EXAMPLE
  3368.                GRADinit();
  3369.  
  3370.        FUNCTIONS INCLUDED
  3371.             cleanup
  3372.  
  3373.        
  3374.        15.1.2  cleanup
  3375.  
  3376.                cleanup(exit_code);
  3377.                int exit_code;
  3378.  
  3379.        RETURN VALUE
  3380.             none
  3381.             
  3382.        DESCRIPTION
  3383.             cleanup must  be  called  if  GRADinit  was  called.  If the
  3384.        exit_code is non-zero,  cleanup will terminate the  program after
  3385.        clean up using the exit code.  If exit_code is zero, cleanup will
  3386.        return control to the caller.
  3387.             
  3388.        EXAMPLE
  3389.                cleanup(1);
  3390.  
  3391.             Cleans up and terminate the program.
  3392.             
  3393.        FUNCTIONS INCLUDED
  3394.             GRADinit
  3395.  
  3396.        
  3397.  
  3398.  
  3399.                                      - 48 -
  3400.  
  3401.  
  3402.  
  3403.  
  3404.  
  3405.        GRAD User's Manual                                    June 7, 1987
  3406.  
  3407.        15.1.3  XHLine
  3408.  
  3409.                ret=XHLine(x,y,boundary,leftx,rightx);
  3410.                int x,y,boundary,*leftx,*rightx;
  3411.                int ret;
  3412.  
  3413.        RETURN VALUE
  3414.             -1  is returned  if  (x,y)  is already in  boundary state or
  3415.        (x,y)  is  outside  the  window.  If  return  value  is  not  -1,
  3416.        coordinates of  the left  most and  right most point  of the line
  3417.        drawn are returned in leftx and rightx.
  3418.             
  3419.        DESCRIPTION
  3420.             You give any point (x,y)  and specify the  boundary state in
  3421.        the search.  A horizontal line will be drawn by extending  to the
  3422.        left  and right.  If value of boundary  is 0,  the drawing of the
  3423.        line in that direction stops when it encounters any  pixel in set
  3424.        state.  If the value of  boundary  is non-zero, the drawing stops
  3425.        when it encounters any pixel in  reset state.  The left  most and
  3426.        right  most  coordinates of the  line is returned.  Of course the
  3427.        line cannot go beyond the  window.  All pixels outside the window
  3428.        are considered in boundary state.
  3429.             
  3430.             The line will be drawn  using current plot  type and current
  3431.        line style.  If the point (x,y) is in boundary state, no dot will
  3432.        be drawn and -1 is returned.
  3433.             
  3434.        EXAMPLE
  3435.                VertLine(50,50,100,1);
  3436.                VertLine(150,50,100,1);
  3437.                XHLine(100,100,0,&leftx, &rightx);
  3438.  
  3439.             XHLine  will  draw  a  horizontal  line  from   (51,100)  to
  3440.        (149,100).  51  and  149  will be  returned  in  leftx and rightx
  3441.        respectively.
  3442.             
  3443.        FUNCTIONS INCLUDED
  3444.             none
  3445.  
  3446.        
  3447.        15.1.4  writec
  3448.  
  3449.                writec(x,y,ch,width,height,options);
  3450.                int x,y,ch,*width,*height,options);
  3451.  
  3452.        RETURN VALUE
  3453.             width and height of the character box are  returned in width
  3454.        and height field in the parameter list.
  3455.             
  3456.        DESCRIPTION
  3457.             writec output a single character (ch) using current selected
  3458.        font to the current frame.  (x,y)  is the reference point for the
  3459.        character.  The actual meaning depends on the  options field. The
  3460.        interpretation of  options is  exactly the  same  as  the options
  3461.        field  in  WriteStr  except  it  does  not have  the text pointer
  3462.        movement options (category D).
  3463.             
  3464.             You should avoid using this function as much as possible.
  3465.  
  3466.                                      - 49 -
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.        GRAD User's Manual                                    June 7, 1987
  3473.  
  3474.  
  3475.        EXAMPLE
  3476.                writec(100,100,0x5f,&width, &height, 0);
  3477.  
  3478.        FUNCTIONS INCLUDED
  3479.             WriteStr, HorzLine, PlotType
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.  
  3505.  
  3506.  
  3507.  
  3508.  
  3509.  
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.                                      - 50 -
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.        GRAD User's Manual                                    June 7, 1987
  3540.  
  3541.        16  Advance Functions
  3542.  
  3543.             In  this  chapter,  all other  GRAD  functions  that  is not
  3544.        described  in  the preceding chapters  will  be  described. These
  3545.        functions are usually more advance.  Only experience users should
  3546.        try to use them. The functions to be described include:
  3547.             
  3548.                calcaddr        calculate address of the coordinate
  3549.                exchange        exchange the upper and lower byte of int
  3550.                fr_read         read a word from the current frame
  3551.                fr_write        write a word to the current frame
  3552.                phyaddr         calculate physical address 
  3553.                writetype       plot type other than AND, OR and XOR
  3554.  
  3555.        
  3556.        16.1  Functions Description
  3557.  
  3558.        16.1.1  calcaddr
  3559.  
  3560.                addr=calcaddr(x,y);
  3561.                int far *addr;
  3562.                int x,y;
  3563.  
  3564.        RETURN VALUE
  3565.             logical address  where  (x,y)  in  current  active  frame is
  3566.        located.
  3567.             
  3568.        DESCRIPTION
  3569.             It  will  calculate the address  where  the  pixel  (x,y) in
  3570.        current frame is located.  The address return may not be physical
  3571.        address.  You  must  not try to  read  or write  it directly. You
  3572.        should use the functions fr_read and fr_write to read and write.
  3573.             
  3574.        EXAMPLE
  3575.                addr=calcaddr(200,100);
  3576.                if (fr_read(addr) & DOTVALUE[200 & 0x0f]) {
  3577.                    printf("pixel (200,100) is set");
  3578.                } else {
  3579.                    printf("pixel (200,100) is reset");
  3580.                }
  3581.  
  3582.        
  3583.  
  3584.        
  3585.        16.1.2  exchange
  3586.  
  3587.                ret=exchange(value);
  3588.                unsigned int ret, value;
  3589.  
  3590.        RETURN VALUE
  3591.             the upper and lower byte of value is  swapped and  return as
  3592.        function result.
  3593.             
  3594.        DESCRIPTION
  3595.             The upper and lower byte of the parameter is swapped.
  3596.             
  3597.        EXAMPLE
  3598.                printf("%4x\n",exchange(0x1234));
  3599.  
  3600.                                      - 51 -
  3601.  
  3602.  
  3603.  
  3604.  
  3605.  
  3606.        GRAD User's Manual                                    June 7, 1987
  3607.  
  3608.  
  3609.             3412 is the value printed.
  3610.  
  3611.        
  3612.        16.1.3  fr_read
  3613.  
  3614.                ret=fr_read(addr);
  3615.                int far *addr;
  3616.                unsigned int ret;
  3617.  
  3618.        RETURN VALUE
  3619.             the value at the logical address addr
  3620.  
  3621.        DESCRIPTION
  3622.             It  reads the value by  the address given.  You  should only
  3623.        read from  the active frame  otherwise it is not  guaranteed that
  3624.        the result is correct.
  3625.             
  3626.        EXAMPLE
  3627.                addr=calcaddr(200,100);
  3628.                if (fr_read(addr) & DOTVALUE[200 & 0x0f]) {
  3629.                    printf("pixel (200,100) is set");
  3630.                } else {
  3631.                    printf("pixel (200,100) is reset");
  3632.                }
  3633.  
  3634.        
  3635.        16.1.4  fr_write
  3636.  
  3637.                fr_read(addr,value);
  3638.                int far *addr;
  3639.                unsigned int value;
  3640.  
  3641.        RETURN VALUE
  3642.             none
  3643.  
  3644.        DESCRIPTION
  3645.             It write the value into  the address given.  You should only
  3646.        write to the active frame otherwise it is not guaranteed that the
  3647.        result is correct. fr_write use the current plot type in writing.
  3648.             
  3649.        EXAMPLE
  3650.                addr=calcaddr(200,100);
  3651.                fr_write(addr, DOTVALUE[200 & 0x0f]);
  3652.  
  3653.             It writes the pixel (200,100).
  3654.  
  3655.        
  3656.        16.1.5  phyaddr
  3657.  
  3658.                addr=phyaddr(x,y);
  3659.                int x,y;
  3660.                int far *addr;
  3661.  
  3662.        RETURN VALUE
  3663.             physical address of the pixel (x,y) in current active frame.
  3664.  
  3665.        DESCRIPTION
  3666.  
  3667.                                      - 52 -
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.        GRAD User's Manual                                    June 7, 1987
  3674.  
  3675.             phyaddr  is  very  similar  to  calcaddr  except  the return
  3676.        address is always a physical address.  If the whole  frame is not
  3677.        accessible  all   the  time  (e.g.   JLASER),  immediately  after
  3678.        execution  of  phyaddr,   the  line  containing   (x,y)  will  be
  3679.        accessible.
  3680.             
  3681.        EXAMPLE
  3682.                int far *addr;
  3683.  
  3684.                addr=phyaddr(x,y);
  3685.  
  3686.        
  3687.        16.1.6  writetype
  3688.  
  3689.                writetype();
  3690.  
  3691.        RETURN VALUE
  3692.             none
  3693.  
  3694.        DESCRIPTION
  3695.             set the plot type to overwrite.  DON'T try to use  it unless
  3696.        you know what you are doing!
  3697.  
  3698.        EXAMPLE
  3699.                writetype();
  3700.  
  3701.  
  3702.  
  3703.  
  3704.  
  3705.  
  3706.  
  3707.  
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.  
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.                                      - 53 -
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.        GRAD User's Manual                                    June 7, 1987
  3741.  
  3742.        17  System Dependent Functions
  3743.  
  3744.             The functions described in  this  chapter  are  not standard
  3745.        GRAD library functions.  That  means they  are not always  in the
  3746.        library.  It depends on the output device configured in your GRAD
  3747.        system you are using.
  3748.  
  3749.        
  3750.        17.1  Functions Description
  3751.  
  3752.        17.1.1  settext
  3753.  
  3754.                settext();
  3755.  
  3756.        RETURN VALUE
  3757.             none
  3758.             
  3759.        DESCRIPTION
  3760.             It  is  available when  Hercules and Color  Graphics Card is
  3761.        used. The function is to change the display mode to text mode.
  3762.             
  3763.        EXAMPLE
  3764.                settext();
  3765.  
  3766.        
  3767.        17.1.2  setgraph
  3768.  
  3769.                setgraph();
  3770.  
  3771.        RETURN VALUE
  3772.             none
  3773.             
  3774.        DESCRIPTION
  3775.             It is  available when  Hercules  or  Color Graphics  Card is
  3776.        used.  The  function  is to change  the display mode  to graphics
  3777.        mode.
  3778.             
  3779.        EXAMPLE
  3780.                settext();
  3781.  
  3782.        
  3783.  
  3784.        17.1.3  initjlsr
  3785.  
  3786.                initjlsr();
  3787.  
  3788.        RETURN VALUE
  3789.             none
  3790.  
  3791.        DESCRIPTION
  3792.             This is  used  to  initialize  the JLASER  mode  to allocate
  3793.        memory for graphics data. You are not normally required to use it
  3794.        because it is included in GRADinit.
  3795.             
  3796.        EXAMPLE
  3797.                initjlsr();
  3798.  
  3799.        
  3800.  
  3801.                                      - 54 -
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.        GRAD User's Manual                                    June 7, 1987
  3808.  
  3809.        17.1.4  cleanjlsr
  3810.  
  3811.                cleanjlsr();
  3812.  
  3813.        RETURN VALUE
  3814.             none
  3815.  
  3816.        DESCRIPTION
  3817.             This is used to clean up the JLASER mode  by deallocate  the
  3818.        memory for graphics data. You are not normally required to use it
  3819.        because it is included in cleanup;
  3820.             
  3821.        EXAMPLE
  3822.                cleanjlsr();
  3823.  
  3824.        
  3825.  
  3826.        17.1.5  dumpjlsr
  3827.  
  3828.                dumpjlsr();
  3829.  
  3830.        RETURN VALUE
  3831.             none
  3832.  
  3833.        DESCRIPTION
  3834.             dumpjlsr will activate JLASER card to dump the memory to the
  3835.        LASER printer.  You may  also  print  the  data  in  memory using
  3836.        PrintFrame.
  3837.             
  3838.        EXAMPLE
  3839.             dumpjlsr();
  3840.  
  3841.  
  3842.  
  3843.  
  3844.  
  3845.  
  3846.  
  3847.  
  3848.  
  3849.  
  3850.  
  3851.  
  3852.  
  3853.  
  3854.  
  3855.  
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865.  
  3866.  
  3867.  
  3868.                                      - 55 -
  3869.  
  3870.  
  3871.  
  3872.  
  3873.  
  3874.        GRAD User's Manual                                    June 7, 1987
  3875.  
  3876.        18  GRAD Global Variables
  3877.  
  3878.             Some of the variables in GRAD may be  used by the  user. You
  3879.        should have at least 2  months of experience with GRAD before you
  3880.        try to use these variables.
  3881.  
  3882.        
  3883.        18.1  TEN_MS
  3884.  
  3885.                int TEN_MS;
  3886.  
  3887.        DESCRIPTION
  3888.             TEN_MS contains  a value that  is proportion to  the central
  3889.        processor speed.  It is only a relative number and  the value may
  3890.        not be the same when GRAD is run twice  in a row  but they should
  3891.        be close.
  3892.             
  3893.             A IBM PC/XT running  at 4.77MHz gives  a count approximately
  3894.        equal to  333.  If  a processor is  ten times  faster,  the value
  3895.        should be about 3330.
  3896.  
  3897.        
  3898.        18.2  DOTVALUE
  3899.  
  3900.                unsigned int DOTVALUE[16]
  3901.  
  3902.        DESCRIPTION
  3903.             DOTVALUE gives the relative  dot position  in  a  word. Each
  3904.        word comprise 16  dots numbered from 0  to 15.  Dot 0 is the left
  3905.        most dot and 15 is the right most dot when display.
  3906.             
  3907.             DOTVALUE[n] where n is number from 0  to 15  gives the value
  3908.        of  the corresponding dot  in  the  word.  See  also  fr_read and
  3909.        fr_write.
  3910.  
  3911.        
  3912.        18.3  PRE_GRAD_ERR_LEVEL, POST_GRAD_ERR_LEVEL
  3913.  
  3914.                int PRE_ERROR_LEVEL, POST_ERROR_LEVEL;
  3915.  
  3916.        DESCRIPTION
  3917.             The error level in GRAD runs  from 0  to 10. PRE_ERROR_LEVEL
  3918.        defines the  lowest error level  you want to take  control before
  3919.        the  GRAD  default  error  handling  routine  process  the error.
  3920.        POST_ERROR_LEVEL defines  the lowest error level you want to take
  3921.        control  after GRAD  default error  handling  routines  print the
  3922.        error message and before it aborts the program or does recovery.
  3923.             
  3924.             See also PRE_ERROR_FUNC,  POST_ERROR_FUNC and error handling
  3925.        in the chapter "Advance Topics".
  3926.  
  3927.        
  3928.        18.4  PRE_ERROR_FUNC, POST_ERROR_FUNC
  3929.  
  3930.                void (*PRE_ERROR_FUNC)(), (*POST_ERROR_FUNC)();
  3931.  
  3932.        DESCRIPTION
  3933.             The declaration of the functions should be like this:
  3934.  
  3935.                                      - 56 -
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.        GRAD User's Manual                                    June 7, 1987
  3942.  
  3943.                
  3944.                #include <stdarg.h>
  3945.                
  3946.                int user_error_routine();
  3947.                extern (*PRE_ERROR_FUNC)();
  3948.                 .
  3949.                 .
  3950.                 .
  3951.                main()
  3952.                {
  3953.                 .
  3954.                 .
  3955.                        PRE_ERROR_LEVEL=4;  /* or the level you want */
  3956.                        PRE_ERROR_FUNC=user_error_routine;
  3957.                 .
  3958.                 .
  3959.                }
  3960.                
  3961.                void user_error_routine(error_level, error_nu, arg_ptr)
  3962.                int error_level, error_nu;
  3963.                va_list arg_ptr;        /* points to additional argument
  3964.                                           from caller */
  3965.                {
  3966.                 .
  3967.                 .
  3968.                }
  3969.                
  3970.             It is similar for POST_ERROR_FUNC.
  3971.  
  3972.        
  3973.        18.5  SPACING_FUNC
  3974.  
  3975.                int (*SPACING_FUNC)();
  3976.  
  3977.        DESCRIPTION
  3978.             This is for used  with  WriteStr.  See the section on "using
  3979.        SPACING_FUNC" in the chapter "Advance Topics".
  3980.             
  3981.  
  3982.        
  3983.        18.6  XLIMIT, YLIMIT
  3984.  
  3985.                int XLIMIT, YLIMIT;
  3986.  
  3987.        DESCRIPTION
  3988.             They are the maximum  physical  coordinates  in  the current
  3989.        frame.  They change when active frame change. You must not change
  3990.        these values.
  3991.  
  3992.        
  3993.        18.7  ORGX, ORGY
  3994.  
  3995.                int ORGX, ORGY;
  3996.  
  3997.        DESCRIPTION
  3998.             (ORGX,  ORGY)  is the  physical coordinate of  the origin in
  3999.        logical coordinate system.
  4000.  
  4001.  
  4002.                                      - 57 -
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.        GRAD User's Manual                                    June 7, 1987
  4009.  
  4010.        18.8  WINX1, WINX2, WINY1, WINY2
  4011.  
  4012.                int WINX1, WINX2, WINY1, WINY2;
  4013.  
  4014.        DESCRIPTION
  4015.             WINX1,  WINX2,  WINY1  and WINY2  stores the lower and upper
  4016.        limit of x coordinate and lower and upper limit  of  y coordinate
  4017.        of the current window respectively.
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.  
  4035.  
  4036.  
  4037.  
  4038.  
  4039.  
  4040.  
  4041.  
  4042.  
  4043.  
  4044.  
  4045.  
  4046.  
  4047.  
  4048.  
  4049.  
  4050.  
  4051.  
  4052.  
  4053.  
  4054.  
  4055.  
  4056.  
  4057.  
  4058.  
  4059.  
  4060.  
  4061.  
  4062.  
  4063.  
  4064.  
  4065.  
  4066.  
  4067.  
  4068.  
  4069.                                      - 58 -
  4070.  
  4071.  
  4072.  
  4073.  
  4074.  
  4075.        GRAD User's Manual                                    June 7, 1987
  4076.  
  4077.        19  Advance Topics
  4078.  
  4079.        19.1  Error Handling
  4080.  
  4081.             When GRAD functions detects a error,  they will call GRADerr
  4082.        with a error level code and error number.  It will issue an error
  4083.        message and takes appropriate  action. However GRAD also provides
  4084.        a  simple  way for  the  users  to  take  control  when  error is
  4085.        detected. There are four variables declared for error handling:
  4086.  
  4087.                int PRE_ERROR_LEVEL, POST_ERROR_LEVEL;
  4088.                void (*PRE_ERROR_FUNC)(), (*POST_ERROR_FUNC)();
  4089.                
  4090.             Firstly,  let's talk  about the  error  level  in  GRAD. All
  4091.        errors in GRAD is classified into 4  categories -- Warning (level
  4092.        2),  Recoverable Error (level  4),  Unrecoverable Error (level 6)
  4093.        and GRAD Program Error (level 10).
  4094.             
  4095.             The default action in GRAD is to print an error  message for
  4096.        all level of error. If that is a level 2 error (warning), it will
  4097.        return  control to  the program.  Otherwise,  it  will  abort the
  4098.        program.
  4099.             
  4100.             You may change the default action of GRADerr by changing the
  4101.        four variables  mentioned  above.  You  may  take  control before
  4102.        GRADerr  issues  an  error message or  after. PRE_ERROR_LEVEL and
  4103.        POST_ERROR_LEVEL defines the lowest  level of  error you  want to
  4104.        see before GRAD issues an error or after. When GRADerr finds that
  4105.        you want to  take control,  it will call the function  defined in
  4106.        PRE_ERROR_FUNC   or   POST_ERROR_FUNC.   If   PRE_ERROR_LEVEL  or
  4107.        POST_ERROR_LEVEL is  greater than  or  equal to  10 (GRAD Program
  4108.        Error),  user error routine will never be  called. GRADerr always
  4109.        handle level 10 and above error.
  4110.             
  4111.             After functions defined in PRE_ERROR_FUNC or POST_ERROR_FUNC
  4112.        have  processed the error situation,  they may  return control to
  4113.        GRADerr, abort the program by calling cleanup or do a longjmp. If
  4114.        user  program takes control using  PRE_ERROR_FUNC,  error message
  4115.        will not be issued by GRADerr even after it takes  control again.
  4116.        However, both PRE_ERROR_FUNC and POST_ERROR_FUNC may be called if
  4117.        error level is greater than PRE_ERROR_LEVEL and POST_ERROR_LEVEL.
  4118.             
  4119.             There is no way to continue the execution of a GRAD function
  4120.        if it detects a error condition with  error level greater  than 2
  4121.        (warning).
  4122.             
  4123.             Users may define  there own error level and  use  GRADerr to
  4124.        handle that.  In that case, you must write your own user handling
  4125.        routine  or  modify GRADerr  (not recommended).  Below is a short
  4126.        example.
  4127.  
  4128.        
  4129.                #include <stdio.h>
  4130.                #include <GRADVAR.h>
  4131.                #include <stdarg.h>
  4132.                
  4133.                void usererror1(), usererror2();
  4134.                
  4135.  
  4136.                                      - 59 -
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.        GRAD User's Manual                                    June 7, 1987
  4143.  
  4144.                main()
  4145.                {
  4146.                    char line[80];
  4147.                
  4148.                    GRADinit();
  4149.                    setgraph();
  4150.                    PRE_ERROR_LEVEL=4;
  4151.                    PRE_ERROR_FUNC=usererror1;
  4152.                    POST_ERROR_LEVEL=2;
  4153.                    POST_ERROR_FUNC=usererror2;
  4154.                    while (1) {
  4155.                        CreateFrame(960,792);
  4156.                        PlotType(1);
  4157.                        HorzLine(10,280,XLIMIT,25);
  4158.                        PlotType(0);
  4159.                        ReadStr(line,80,10,300,2,0x5f,0x5f);
  4160.                        LoadFont(line);
  4161.                    }
  4162.                }
  4163.                
  4164.                void usererror1(errlevel, errnu, arg_ptr)
  4165.                int errlevel, errnu;
  4166.                va_list arg_ptr;
  4167.                {
  4168.                    extern char *GRADERRMSG[];
  4169.                
  4170.                    printf("I am usererror 1:");
  4171.                    vprintf(GRADERRMSG[errnu],arg_ptr);
  4172.                    printf("\n");
  4173.                }
  4174.                
  4175.                void usererror2(errlevel, errnu, arg_ptr)
  4176.                int errlevel, errnu;
  4177.                va_list arg_ptr;
  4178.                {
  4179.                    printf("I am usererror2\n");
  4180.                }
  4181.                
  4182.             
  4183.             This program will  get error very  soon.  You can  type in a
  4184.        wrong font  file  name  and get a level  2  error.  After several
  4185.        times,  you will get out of memory  error (level  6) because each
  4186.        new frame occupy almost 93K bytes of memory. 
  4187.  
  4188.        
  4189.        19.2  Using SPACING_FUNC
  4190.  
  4191.             The function which address is stored  in SPACING_FUNC should
  4192.        return a integer.  Zero  means go  on.  A  non-zero  values tells
  4193.        WriteStr to stop immediately.  It may also modify  the content of
  4194.        the some of the variables  in WriteStr through the  address given
  4195.        in the parameters.
  4196.             
  4197.             Below is a simple example of using SPACING_FUNC. The spacing
  4198.        between the characters increase by 2 every time.
  4199.                
  4200.                #include <stdio.h>
  4201.                #include <GRADVAR.h>
  4202.  
  4203.                                      - 60 -
  4204.  
  4205.  
  4206.  
  4207.  
  4208.  
  4209.        GRAD User's Manual                                    June 7, 1987
  4210.  
  4211.                #include <GRADio.h>
  4212.                
  4213.                int increasing();
  4214.                
  4215.                int spacing;
  4216.                
  4217.                main()
  4218.                {  int x,y;
  4219.                
  4220.                   GRADinit();
  4221.                   setgraph();
  4222.                   spacing=0;
  4223.                   SPACING_FUNC=increasing;
  4224.                   WriteStr(VAR_MOVE,0,10,100,
  4225.                           "This is a special test 123456",0,0);
  4226.                   getch();
  4227.                   settext();
  4228.                   cleanup(0);
  4229.                }
  4230.                
  4231.                increasing(curx, cury, w, h, remaining)
  4232.                int *curx, *cury, w, h;
  4233.                char *remaining;
  4234.                {
  4235.                    *curx+=w+spacing;
  4236.                    spacing+=2;
  4237.                    return(0);
  4238.                }
  4239.                
  4240.  
  4241.             The  function increasing will  only get  control if VAR_MOVE
  4242.        option is used in WriteStr.  Every time when it gets  control, it
  4243.        has five  parameters  --  curx,  cury is  the  coordinate  of the
  4244.        reference point of  the character just  written.  w and h are the
  4245.        width and height  of  the character  box  of  the  character just
  4246.        written.  remaining points to the remaining part of the string to
  4247.        be written.  You may modify the remaining part  of  the string on
  4248.        the fly.  For example,  you may set the next character to null so
  4249.        that  WriteStr  will  terminate immediately.  Of  course  you may
  4250.        return a non-zero value to terminate WriteStr too.
  4251.             
  4252.             Another application of SPACING_FUNC is  to do justification.
  4253.        On the first  call  to  WriteStr,  specify  NO_WRITE  and collect
  4254.        information  on  the line.  Then call  WriteStr  again  to insert
  4255.        microspaces to justify the line.
  4256.             
  4257.             Within  SPACING_FUNC,  you  may  call  other  GRAD functions
  4258.        including  WriteStr  too!  But  be  careful,  the  loop  must  be
  4259.        terminate in some way,  otherwise you will get the stack overflow
  4260.        error very soon.
  4261.  
  4262.  
  4263.  
  4264.  
  4265.  
  4266.  
  4267.  
  4268.  
  4269.  
  4270.                                      - 61 -
  4271.  
  4272.  
  4273.  
  4274.  
  4275.  
  4276.        GRAD User's Manual                                    June 7, 1987
  4277.  
  4278.        20  Sample Programs
  4279.  
  4280.        20.1  MPrint and Interp
  4281.  
  4282.        USAGE
  4283.                MPrint [options] GRAD-command-file text-file-to-be merge
  4284.  
  4285.                Interp GRAD-command-file
  4286.  
  4287.        EXAMPLE
  4288.                Mprint -v1 test.gcm test.txt
  4289.  
  4290.             Print graphics data in high density.
  4291.  
  4292.        DESCRIPTION
  4293.             Below are the simple syntax rules for Interp and Mprint.
  4294.  
  4295.           ` ' means optional, | means or , { } means selection
  4296.  
  4297.           STMT := [ VARIABLE = ] FUNCTION
  4298.           VARIABLE := identifier
  4299.           FUNCTION := identifier ( PARAMETERS ) ;
  4300.           PARAMETERS := PARAMETER , PARAMETERS | PARAMETER
  4301.           PARAMETER := EXPRESSION
  4302.  
  4303.           EXPRESSION := NUMBER | STRING | VARIABLE | & VARIABLE | COLUMN
  4304.                           | LINE
  4305.           NUMBER := +NATURAL | -NATURAL
  4306.           NATURAL := 0xHHHH | decimal digits
  4307.           STRINGS := "character string"
  4308.           H := decimal digits | A | B | C | D | E | F | a | b | c
  4309.                   | d | e | f
  4310.           COLUMN := [ {C|c}NATURAL `, NATURAL' ]
  4311.           LINE := [ {L|l}NATURAL `, NATURAL' ]
  4312.  
  4313.             
  4314.             In  order to  facilitate  the calculation the coordinates on
  4315.        the  paper in  MPrint,  you may specify a coordinate in  terms of
  4316.        line and column number. Both line and column number start from 1.
  4317.        The  calculations  are based on  the character  width  and height
  4318.        setting.  You may change those values using  command line options
  4319.        in Mprint but Interp always use the default values in Mprint.
  4320.             
  4321.             No  variables can be  declared  but there  are  a  number of
  4322.        pre-declared variables.
  4323.          a. temp1,  temp2, temp3, env1, env2, env3, font1, font2, font3,
  4324.             font4,  frame1,  frame2,  frame3,  x1,  x2,  y1,  y2 are all
  4325.             integer variables.
  4326.          
  4327.          b. line is a character pointer to a 132-byte area. It is mainly
  4328.             for ReadStr function.
  4329.          
  4330.          c. pattern1,  pattern2  and pattern3 are pattern definition for
  4331.             use with PatternFill only.
  4332.          
  4333.             
  4334.  
  4335.  
  4336.  
  4337.                                      - 62 -
  4338.  
  4339.  
  4340.  
  4341.  
  4342.  
  4343.        GRAD User's Manual                                    June 7, 1987
  4344.  
  4345.             '&'  operator can only be used with integer  variables only.
  4346.        Moreover, only integer variables can appear on the left hand side
  4347.        of '=' (assignment).
  4348.             
  4349.             No any kind  of  arithmetic  operations  is  allowed in both
  4350.        Mprint  and  Interp.  However,  you  may  draw  lines  with  same
  4351.        coordinate numbers but at different location by setting origin at
  4352.        different coordinates.
  4353.             
  4354.             PrintPage  in  Interp  is  a  dummy  function.  Execution of
  4355.        PrintPage  in  Interp  will  suspend  the  interpretation  of the
  4356.        command  file  until  any   key  is  pressed  on   the  keyboard.
  4357.        Furthermore, after a key is pressed, the screen will be cleared.
  4358.             
  4359.             PrintPage  in Mprint will  merge print the  current selected
  4360.        frame and the text file if  specified.  The frame will be cleared
  4361.        after printing.
  4362.             
  4363.             MPrint also  provides  a  number  of  options  which  is not
  4364.        provided in Interp. The number inside the parentheses
  4365.             
  4366.           -W   frame width (960)
  4367.           -H   frame height (792)
  4368.           -w   character width in terms of pixels (12)
  4369.           -h   character height in terms of pixels (12)
  4370.           -c   column offset (0)
  4371.           -r   row offset (0)
  4372.           -p   line per page (66)
  4373.           -d   horizontal density (4)
  4374.           -v   vertical density (0)
  4375.           
  4376.             All the default value is for EPSON printer.  You may need to
  4377.        change the default values for different printer.
  4378.             
  4379.             There are a number of examples  for MPrint  and Interp. They
  4380.        illustrate most  of  the features  of Interp and MPrint.  You can
  4381.        learn a lot more about GRAD library by studying those examples.
  4382.  
  4383.        
  4384.        20.2  Rotate
  4385.  
  4386.        USAGE
  4387.                rotate input-FON-file output-FON-file
  4388.  
  4389.        EXAMPLE
  4390.                rotate AMR7.fon AMR7U.fon
  4391.  
  4392.        DESCRIPTION
  4393.             The input and output font file name cannot be the  same. The
  4394.        naming convention is to  append U,  R or D after the  normal font
  4395.        file name  to  indicate  that  font file is  normally for writing
  4396.        upward, to the right or downward.
  4397.             
  4398.             This  program will  rotate  a  font  file  in anti-clockwise
  4399.        direction  for 90  degree.  For example,  AMR7.fon after rotation
  4400.        should have the name AMR7U.fon.  If it is rotated again, the file
  4401.        name should become AMR7R.fon.
  4402.  
  4403.  
  4404.                                      - 63 -
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410.        GRAD User's Manual                                    June 7, 1987
  4411.  
  4412.        20.3  Size
  4413.  
  4414.        USAGE
  4415.                size -s# [options] input-file output-file
  4416.  
  4417.        EXAMPLE
  4418.                size -s1 e6x8.fon e12x8.fon
  4419.  
  4420.        DESCRIPTION
  4421.             This program  is  to  change  the  size  of  the  font file.
  4422.        Allowable options are:
  4423.             
  4424.           -s0  reduce height by half
  4425.           -s1  double the height
  4426.           -s2  double the width
  4427.           -m0  ink dominate    (default)
  4428.           -m1  prefer ink
  4429.           -m2  prefer white space
  4430.           -m3  white space dominate
  4431.           
  4432.             -m option is only useful in reducing  the size  of the font.
  4433.        During reduction,  several pixels will be reduced to 1  pixel. If
  4434.        ink donimate option is used,  the resulting pixel is black if any
  4435.        one  of  the source  pixels  is black.  Similarly for white space
  4436.        dominate.  If prefer ink option  is used,  the resulting pixel is
  4437.        black if the number of black pixel is  more than or  equal to the
  4438.        number of white pixel.  If prefer white space option is used, the
  4439.        resulting  pixel is  black if the  number of black pixel  is MORE
  4440.        than the number of white pixel.
  4441.             
  4442.             In  this version  of size,  -m0  and -m1, -m2 and-m3 are the
  4443.        same. In order to provide future compatibility, all 4 options are
  4444.        valid.
  4445.  
  4446.        
  4447.        20.4  DispFont
  4448.  
  4449.        USAGE
  4450.                DispFont
  4451.  
  4452.        DESCRIPTION
  4453.             Enter a font file name when it asks for one. Enter the ASCII
  4454.        code  of  the character you want  to  see.  The character and the
  4455.        enlarger  character will  be  displayed.  A return  or a negative
  4456.        ASCII number will terminate the program.
  4457.  
  4458.        
  4459.        20.5  SwPrt (Sideway)
  4460.  
  4461.        USAGE
  4462.                swprt [options] text-file-name
  4463.  
  4464.        EXAMPLE
  4465.                swprt -fAMR7D.fon -s35 -H1920 -W792 -L3 -v1 -d3 test.txt
  4466.  
  4467.        DESCRIPTION
  4468.             The options provided are: (values inside parentheses are the
  4469.        default value)
  4470.  
  4471.                                      - 64 -
  4472.  
  4473.  
  4474.  
  4475.  
  4476.  
  4477.        GRAD User's Manual                                    June 7, 1987
  4478.  
  4479.            
  4480.            -W  Width of the print out (792).  This is the  length of the
  4481.                frame created for output.  This value should  be a simple
  4482.                fraction (1/2,  1/3 or 1/4) or a integral multiple of the
  4483.                length of paper.  If -v1 (described below) option is used
  4484.                and -L (described below also)  is set to a  value greater
  4485.                than 1,  the width should  be a integral multiple  of the
  4486.                number of  vertical unit per point.  In  other words, for
  4487.                EPSON printer, the value is 3, for OKI Microline 192, the
  4488.                value is 2.
  4489.            
  4490.            -H  Height of the print out (960).  This is the  width of the
  4491.                paper.  This number is related to  the horizontal density
  4492.                (-d option) setting.
  4493.            
  4494.            -v  Vertical  density   (0).   Any  non-zero  value  will  be
  4495.                considered as 1. See PrintFrame for explanation.
  4496.            
  4497.            -d  Horizontal  density   (4).   Also   see   PrintFrame  for
  4498.                explanation.  This value is  suitable  for  EPSON printer
  4499.                only.  You should set it to 2 for OKI printer if you want
  4500.                to use other default values.
  4501.            
  4502.            -s  Spacing between any 2  base line (11). This value is very
  4503.                likely to  be changed  when different font file  is used.
  4504.                See -f option below.
  4505.            
  4506.            -f  Font file  name.  (S6X8D.fon)  This  is the  font used in
  4507.                printing.  When use  other font file,  remember to change
  4508.                the  spacing  between  lines  using  -s  option described
  4509.                above.
  4510.            
  4511.            -t  Top margin (36).  This is the margin on the right side of
  4512.                the paper.
  4513.            
  4514.            -b  Bottom margin (36).  This is the margin on the  left side
  4515.                of the paper.
  4516.            
  4517.            -L  Text length (1). This field controls the number of 'page'
  4518.                for the text.  If text length is set to 2, that means the
  4519.                width of the text is  twice the specified width  (-W). In
  4520.                this way, you may print very long data without creating a
  4521.                very  large frame.  The -L  setting times the  -W setting
  4522.                must  not exceed  30000.  This value should be  more than
  4523.                enough.
  4524.  
  4525.             The default values will print 132 characters by 80 lines per
  4526.        page on a EPSON compatible printer.
  4527.  
  4528.        
  4529.        20.6  Tex2GRAD
  4530.  
  4531.        USAGE
  4532.                TeX2GRAD TeX-PXL-file GRAD-FON-file
  4533.  
  4534.        EXAMPLE
  4535.                TeX2GRAD amr10.pxl amr10.fon
  4536.  
  4537.  
  4538.                                      - 65 -
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.        GRAD User's Manual                                    June 7, 1987
  4545.  
  4546.        DESCRIPTION
  4547.             TeX2GRAD  converts  a TeX pixel  files  to  GRAD  font file.
  4548.        During the conversion, ASCII character 32 (' ') is forced to be a
  4549.        space with width equal to 9/16 of the design size.
  4550.             
  4551.             The TeX pixel file must  be a  type 1002  pixel file and the
  4552.        magnification  field in the file  must contain  the resolution of
  4553.        the output  device  the pixel file  is designed for times  5. For
  4554.        example,  a pixel file  for  a  laser  printer  with  300dpi, the
  4555.        magnification  field must contain 1500  decimal.  The pixel files
  4556.        from TEXTSET meets all of the above requirements.
  4557.  
  4558.  
  4559.  
  4560.  
  4561.  
  4562.  
  4563.  
  4564.  
  4565.  
  4566.  
  4567.  
  4568.  
  4569.  
  4570.  
  4571.  
  4572.  
  4573.  
  4574.  
  4575.  
  4576.  
  4577.  
  4578.  
  4579.  
  4580.  
  4581.  
  4582.  
  4583.  
  4584.  
  4585.  
  4586.  
  4587.  
  4588.  
  4589.  
  4590.  
  4591.  
  4592.  
  4593.  
  4594.  
  4595.  
  4596.  
  4597.  
  4598.  
  4599.  
  4600.  
  4601.  
  4602.  
  4603.  
  4604.  
  4605.                                      - 66 -
  4606.  
  4607.  
  4608.  
  4609.  
  4610.  
  4611.        GRAD User's Manual                                    June 7, 1987
  4612.  
  4613.        Appendix A : Customizing of Printer Control Codes
  4614.  
  4615.        General Information
  4616.  
  4617.             Two printer  drivers  for  EPSON  FX-80  and  OKI  ML192 are
  4618.        distributed  with  the GRAD  library.  If  you have  one of these
  4619.        printers or  a  compatible  one,  you  just  need  to  follow the
  4620.        installation instruction and you will  be  able to print  on your
  4621.        printer. Otherwise, go on reading this chapter.
  4622.             
  4623.             You can only  configure GRAD  to use 8  bit graphics printer
  4624.        with the information here and the included source  files. If your
  4625.        graphics printer is 24-pin printer or it only accepts 7 bit data,
  4626.        you need the source code of GRAD library to do the configuration.
  4627.        Information for special customizing accompany the source code.
  4628.             
  4629.             To do customizing, you need a Microsoft C compiler version 4
  4630.        and you may need a macro assembler also in some cases.
  4631.             
  4632.             There are three files involved in the customizing process.
  4633.          a. prtcntl.c defines the  control  code  sequence  for printing
  4634.             graphics and paper feeding.
  4635.          b. prt.asm  contains routines for converting  data  in frame to
  4636.             data for printing.
  4637.          c. pframe controls  the number  of dots printer  vertically per
  4638.             pass and the number of dots per point.
  4639.          
  4640.             Each  of  these will  be  discussed later.  Firstly,  let me
  4641.        define some  of  the terms first.  A point in  publishing means a
  4642.        length approximately equal to  1/72  inch.  However, a point here
  4643.        means  the distance  between 2  pins on the  print head. Vertical
  4644.        unit  is  the  smallest  distance  that  the  printer   can  move
  4645.        vertically.  The length  of  both  point  and  vertical  unit are
  4646.        printer dependent.  However, a point must be an integral multiple
  4647.        (can be 1) of vertical unit.
  4648.             
  4649.        a. prtcntl.c
  4650.             In prtcntl.c,  there are 8 variables declared. 5 of them are
  4651.        structure prtcmd.  prtcmd is used to store printer  control codes
  4652.        sequence. It contains 5 members.
  4653.             
  4654.             length  the length of the sequence from 0 to 8.
  4655.             factor  the number that will multiple with the number to be
  4656.                     included in the control sequence.
  4657.             numh    the high order byte of the scaled number in the
  4658.                     sequence. The value can be from -1 to length-1. -1
  4659.                     means the high order byte is not used.
  4660.             numl    the low order byte of the scaled number in the
  4661.                     sequence. The value can be from -1 to length-1. -1
  4662.                     means the low order byte is not used.
  4663.             code    the code sequence is stored here. Max. number of
  4664.                     character is 8.
  4665.             
  4666.             GRAD requires 5 kind of control sequences.
  4667.             
  4668.             skp     control sequence for moving the paper forward a
  4669.                     certain number of points. Note, it is point not
  4670.                     vertical unit.
  4671.  
  4672.                                      - 67 -
  4673.  
  4674.  
  4675.  
  4676.  
  4677.  
  4678.        GRAD User's Manual                                    June 7, 1987
  4679.  
  4680.             skd     control sequence for moving the paper forward a
  4681.                     certain number of vertical unit. Only used when
  4682.                     SMALL_DOT option is used in PrintFrame.
  4683.             setp    set the line feed spacing of the printer to the
  4684.                     specified number of points. It is only used at the
  4685.                     end of PrintFrame to set the printer back to six
  4686.                     line per inch. If skp and skd does not affect the
  4687.                     line feed spacing, you may set setp to null by
  4688.                     setting the length field to 0.
  4689.             header  is a array of struct prtcmd. It contains control
  4690.                     sequence to turn the printer into different density
  4691.                     graphics mode. The sequence is output immediately
  4692.                     before the graphics data.
  4693.             endg    contains the control sequence that append at the end
  4694.                     of graphics data in order to terminate the graphics
  4695.                     mode and cause the printer to actually print out the
  4696.                     data.
  4697.             
  4698.        Other 3 variables are:
  4699.             
  4700.             MAXPSIZ is the maximum number of dots that the printer can
  4701.                     print in different density.
  4702.             NHEADER contains the number of entries in the array header
  4703.                     and MAXPSIZ. Don't forget to change this number when
  4704.                     you change the number of entries in header and
  4705.                     MAXPSIZ.
  4706.             sixlpi  is the value that will be used with setp to set the
  4707.                     printer back to 6 line per inch at the end of
  4708.                     PrintFrame.
  4709.             
  4710.        b. prt.asm
  4711.             It is a assembly  program to  convert data in frame  to data
  4712.        for printing.  The data in a frame is stored line by line and the
  4713.        printer  usually requires  data  to be send  8  (or more) lines a
  4714.        time. prt is the routine for conversion. prtgc is the routine for
  4715.        putting  data  into  the  buffer  and  optionally  do  additional
  4716.        checking for special  pattern.  See  the  case  studies  for more
  4717.        information.
  4718.             
  4719.        c. pframe.obj
  4720.             pframe controls the number  of vertical dots  sent each time
  4721.        and the number of vertical unit per point.  Source code of pframe
  4722.        is  not  included  with  GRAD  library.  However  two  version of
  4723.        pframe.obj is provided: (1) 8 dots each time and 3 vertical units
  4724.        per point (EPSON FX-80) (2) 8 dots each time and 2 vertical units
  4725.        per point (OKI ML192).
  4726.             
  4727.             
  4728.             In the remaining part of the chapter, we will study the code
  4729.        for EPSON printer and OKI printer in  order to  provide a example
  4730.        of customizing.
  4731.  
  4732.        
  4733.  
  4734.  
  4735.  
  4736.  
  4737.  
  4738.  
  4739.                                      - 68 -
  4740.  
  4741.  
  4742.  
  4743.  
  4744.  
  4745.        GRAD User's Manual                                    June 7, 1987
  4746.  
  4747.        EPSON FX-80 Driver Case Study
  4748.  
  4749.             IN EPSON FX-80  printer, it does not have a control sequence
  4750.        to forward the paper a specified number  of points.  So I have to
  4751.        set the line spacing to  the desired number  and do  a line feed.
  4752.        The sequence  for setting line spacing is  3  characters long and
  4753.        the fourth character is a line feed.
  4754.             
  4755.             The  length  of  each  vertical  unit is 1/216  inch but the
  4756.        length  of  a point is  1/72  =  3/216 inch. Therefore the factor
  4757.        field is  3  in skp.  Only  a one byte  value is  allowed  in the
  4758.        control sequence so the numh  field is  set to -1  (not used) and
  4759.        numl is set to 2  (the third character).  skd is set in a similar
  4760.        way except the factor field is 1  this time.  If you have a EPSON
  4761.        FX-80  manual,  you would  find  that  the  control  sequence for
  4762.        setting line  spacing is  not the same  as defined  in setp. setp
  4763.        contains two extra characters. These are for IBM graphics printer
  4764.        or compatibles but it should still work for FX-80 printer.
  4765.             
  4766.             EPSON printer requires a length field as part of the control
  4767.        sequence for graphics printing.  It requires the total  number of
  4768.        bytes of graphics data following the sequence.  The  length field
  4769.        is 16 bit. Therefore both the numh and numl fields are set.
  4770.             
  4771.             If your printer don't have 80  dots per inch  mode (640 dots
  4772.        per line on 8 inch paper), you may used the sequence for 240 dots
  4773.        per  inch  and  set  the  factor  field  to  3.  PrintFrame  will
  4774.        automatically insert 2  null characters after  each graphics data
  4775.        byte.
  4776.             
  4777.             endg for EPSON is just a return character.
  4778.             
  4779.             MAXPSIZ values are the number of  dots per inch times  8. If
  4780.        you have a FX-100,  the values should  be the number of  dots per
  4781.        inch times 13.5.
  4782.             
  4783.             If you look at prt.asm,  you would find  that the difference
  4784.        between EPSON and OKI driver is in two main area. Firstly in prt,
  4785.        FX-80  mode use rcl (rotate circular left) while OKI mode use rcr
  4786.        (rotate circular right).  It is because the least significant bit
  4787.        of each byte is printed at the bottom in FX-80  but it is printed
  4788.        at the top in ML192.  Another difference is in prtgc.  OKI has an
  4789.        additional check for 03.  It will be explained in the  case study
  4790.        for OKI ML192.
  4791.  
  4792.        
  4793.        OKI ML192 Driver Case Study
  4794.  
  4795.             OKI ML192  use a  scheme completely different from  FX-80 in
  4796.        printing graphics.  It has control sequence  for forwarding paper
  4797.        without  changing  the line  spacing setting.  Therefore  no setp
  4798.        sequence is  required.  Furthermore,  the line spacing before and
  4799.        after printing is the same and it may not be six line per inch.
  4800.             
  4801.             In ML192, it uses the control code 03 to enter graphics mode
  4802.        and  the sequence  03  02  to  exit from graphics  mode. No total
  4803.        length of  data  is  required  to  send  to  the printer.  If the
  4804.        graphics data  contains the pattern  03,  it has to be duplicated
  4805.  
  4806.                                      - 69 -
  4807.  
  4808.  
  4809.  
  4810.  
  4811.  
  4812.        GRAD User's Manual                                    June 7, 1987
  4813.  
  4814.        (i.e.  03  03)  to indicate the 03 is a data byte and not command
  4815.        code.  This  is  the   reason  for a special checking  for  03 in
  4816.        prt.asm in OKI mode.
  4817.             
  4818.             endg contains  03  02  to  indicate  end of  data  which are
  4819.        appended at the end of graphics data.
  4820.             
  4821.             sixlpi is not  used in OKI driver.  Therefore it can  be any
  4822.        value but it has to be defined.
  4823.  
  4824.        
  4825.        Additional Information
  4826.  
  4827.             Before you do the customizing,  you should first  try to see
  4828.        any  body  has done  the customizing for  your  printer  make the
  4829.        driver available on the BBS.
  4830.             
  4831.             When  you do  the customizing,  probably you  need to modify
  4832.        prtcntl.c  yourself.  But  you may  not  need  to  modify prt.asm
  4833.        because you may use the OKI or EPSON version.  Then  you choose a
  4834.        suitable version of  pframe  for  your  printer.  If  you  need a
  4835.        special version of pframe, you have to either buy the source code
  4836.        or  see other printer drivers available have  a  version suitable
  4837.        for you or not.  With the source  code and the knowledge of C and
  4838.        assembly language,  customizing for most kind of  printer will be
  4839.        easy. Additional information is provided with source code.
  4840.  
  4841.  
  4842.  
  4843.  
  4844.  
  4845.  
  4846.  
  4847.  
  4848.  
  4849.  
  4850.  
  4851.  
  4852.  
  4853.  
  4854.  
  4855.  
  4856.  
  4857.  
  4858.  
  4859.  
  4860.  
  4861.  
  4862.  
  4863.  
  4864.  
  4865.  
  4866.  
  4867.  
  4868.  
  4869.  
  4870.  
  4871.  
  4872.  
  4873.                                      - 70 -
  4874.  
  4875.  
  4876.  
  4877.  
  4878.  
  4879.        GRAD User's Manual                                    June 7, 1987
  4880.  
  4881.        Appendix B : Customizing of Output Device
  4882.  
  4883.             Customizing for output device have a lot  of variations. You
  4884.        may only need to change a single line to rewrite several routines
  4885.        in customizing.  You also need some experiences  with GRAD before
  4886.        trying  to  do  customizing  otherwise  it  is   very  difficult.
  4887.        Therefore  only  general information will  be  given.  You should
  4888.        study the source codes provided yourself to find out what  do you
  4889.        need to change.
  4890.             
  4891.             Three  routines   are  related  to  customizing.   They  are
  4892.        calcaddr.asm,  plottype.asm and ftable.c.  Most  of  the hardware
  4893.        dependent  values  are  defined  in  calcaddr.asm  including  the
  4894.        address of  video memory,  default  font pattern  address and the
  4895.        routines for calculating address  by giving x and  y coordinates.
  4896.        plottype.asm contains the lowest  level memory  accessing routine
  4897.        for reading and writing.  ftable.c contain code for  defining the
  4898.        characteristics of the output device.
  4899.  
  4900.             Three  drivers  are  provided  for  Color  graphics adapter,
  4901.        Hercules graphics adapter (full or half mode) and JLASER card. 
  4902.  
  4903.  
  4904.  
  4905.  
  4906.  
  4907.  
  4908.  
  4909.  
  4910.  
  4911.  
  4912.  
  4913.  
  4914.  
  4915.  
  4916.  
  4917.  
  4918.  
  4919.  
  4920.  
  4921.  
  4922.  
  4923.  
  4924.  
  4925.  
  4926.  
  4927.  
  4928.  
  4929.  
  4930.  
  4931.  
  4932.  
  4933.  
  4934.  
  4935.  
  4936.  
  4937.  
  4938.  
  4939.  
  4940.                                      - 71 -
  4941.  
  4942.  
  4943.  
  4944.  
  4945.  
  4946.        GRAD User's Manual                                    June 7, 1987
  4947.  
  4948.        Appendix C : Font File Structure
  4949.  
  4950.             There are 2 types of font files. They are distinguish by the
  4951.        type code  stored  in  each  font  file.  Each  of  them  will be
  4952.        described separately.
  4953.  
  4954.        
  4955.        Fixed Size Character (type 0)
  4956.  
  4957.             The File format is  shown below.  If that field is  a 2 byte
  4958.        integer,  lower byte (less significant)  will be stored first and
  4959.        then the higher  byte  (more significant).  The  word  inside the
  4960.        bracket is the field name.
  4961.             
  4962.           Byte         Description
  4963.           0            ID = 51 decimal
  4964.           1 to n-1     [comment] A string in ASCII terminated by a NULL
  4965.                        character. The string can be any length less than
  4966.                        or equal to 255.
  4967.           n            [type] The type code. 0 in fixed size font file
  4968.           n+1, n+2     [nochar] Number of character in this file
  4969.           n+3, n+4     [start] The starting number. For example, only
  4970.                        pattern for graphic ASCII characters are
  4971.                        available. That means the first pattern is for
  4972.                        ASCII 0x20. Therefore, this field should contains
  4973.                        0x0020.
  4974.           
  4975.           /* the fields below will be described in more detail later */
  4976.           n+5          [width] width of the character cell
  4977.           n+6          [ink-width] ink width of the pattern
  4978.           n+7          [ink-height] ink height of the pattern
  4979.           n+8          [left-margin] left-margin of the pattern
  4980.           n+9          [top-line] the highest line number
  4981.           n+10         [cell-height] height of the character cell
  4982.           n+11         [default] the default character number
  4983.           n+12 to n+15 reserved
  4984.           
  4985.           n+16 to end of file are the pattern information
  4986.           
  4987.             Let's  take  an   example  using  E9X14.fon   (a  font  file
  4988.        containing 9  by 14  patterns). The vales for byte n to byte n+11
  4989.        are:
  4990.             
  4991.             00 00 01 00   00 09 08 0E   00 0A 0E 7F
  4992.             
  4993.             The font file contains pattern in the format of  type 0 (1st
  4994.        byte).  The number of pattern is  256  (0x0100 2nd and 3rd bytes)
  4995.        and it starts it ASCII 0  (0x0000 4th and 5th byte). The width of
  4996.        each  character including spacing  is  9  dots  (0x09  6th byte).
  4997.        However,  only 8  dots (0x08  7th byte)  of data are given in the
  4998.        file  and the pattern given starts  at  the first  dot  (0x00 9th
  4999.        byte).  So  the 9th dots  is assumed to be  0.  The height of the
  5000.        character cell is 14  (0x0E 8th byte).  The pattern starts  at 10
  5001.        lines above the base  line.  That means the descendent  part is 3
  5002.        dots.  If a character given does not have a corresponding pattern
  5003.        in  the file  (greater than 255),  the ASCII  character 255 (0x7f
  5004.        last byte) will be written instead.
  5005.             
  5006.  
  5007.                                      - 72 -
  5008.  
  5009.  
  5010.  
  5011.  
  5012.  
  5013.        GRAD User's Manual                                    June 7, 1987
  5014.  
  5015.             The  pattern is  stored  line  by line according to  the ink
  5016.        width and ink height.  For  example,  a character pattern  of ink
  5017.        width equal to 9 and height equal to 14. 28 bytes are required to
  5018.        store one character.  The character when  display is  in the form
  5019.        below:
  5020.             
  5021.                             0     7 8    15
  5022.                            +-------+-------+
  5023.                            |   0   |   1   |
  5024.                            +-------+-------+
  5025.                            |   2   |   3   |
  5026.                            +-------+-------+
  5027.                              . . . . . . .
  5028.                            +-------+-------+
  5029.                            |   26  |   27  |
  5030.                            +-------+-------+
  5031.                            
  5032.             Only bits 0 to 8 of every 2 bytes are used. 
  5033.  
  5034.        
  5035.        Variable Size Character (type 1)
  5036.  
  5037.             The File format is  shown below.  If that field is  a 2 byte
  5038.        integer,  lower byte (less significant)  will be stored first and
  5039.        then the higher  byte  (more significant).  The  word  inside the
  5040.        bracket is the field name.
  5041.             
  5042.           Byte         Description
  5043.           0            ID = 51 decimal
  5044.           1 to n-1     [comment] A string in ASCII terminated by a NULL
  5045.                        character. The string can be any length less than
  5046.                        or equal to 255.
  5047.           n            [type] The type code. 1 in variable size font
  5048.                        file
  5049.           n+1, n+2     [nochar] Number of character in this file
  5050.           n+3, n+4     [start] The starting number. For example, only
  5051.                        pattern for graphic ASCII characters are
  5052.                        available. That means the first pattern is for
  5053.                        ASCII 0x20. Therefore, this field should contains
  5054.                        0x0020.
  5055.           
  5056.           n+5 to n+7   reserved
  5057.           n+8          [default] the default character number
  5058.           n+9 to n+15  reserved
  5059.           
  5060.           n+16 to n+21 width, ink width, left margin, top line, cell
  5061.                        height information of first character.
  5062.           n+22 to n+27 same kind of information for second character.
  5063.            .
  5064.            .           information of all characters in the file
  5065.            .
  5066.           n+16+6*nochar to end of the file are the pattern data of the
  5067.                        characters
  5068.           
  5069.             The pattern data  are stored  exactly  as  described  in the
  5070.        section  for  fixed  size  character  except  each  character are
  5071.        independent of each other.
  5072.  
  5073.  
  5074.                                      - 73 -
  5075.  
  5076.  
  5077.  
  5078.  
  5079.  
  5080.        GRAD User's Manual                                    June 7, 1987
  5081.  
  5082.        Appendix D : Block File Structure
  5083.  
  5084.             The format  of  a block file  is very simple.  It contains a
  5085.        header and then comes the data. The structure when represented in
  5086.        C syntax is like this:
  5087.             
  5088.                struct header_format {
  5089.                        unsigned char ID;
  5090.                        unsigned int header_length : 4;
  5091.                        unsigned int x_offset : 4;
  5092.                        int length, height;
  5093.                        int dummy;
  5094.                } ;
  5095.                
  5096.                struct blockfile {
  5097.                        struct header_format header;
  5098.                        int data[height][((x_offset+length+15) >> 4)];
  5099.                };
  5100.                
  5101.             The  ID  is  equal   to  101   decimal   in   this  version.
  5102.        header_length is in term of 4-bytes. That means the length of the
  5103.        header must be  multiple of 4  bytes.  The header_length field in
  5104.        block files created by GRAD contain the value 2  now  because the
  5105.        header length is  6  bytes plus 2  byte dummy. The maximum header
  5106.        length is hence 64 bytes. You may include your own information in
  5107.        the header but remember to change the header_length field.
  5108.             
  5109.             We  will return to  x_offset later.  Let's talk about length
  5110.        and  height  fields first.  length and height  contain the actual
  5111.        number  of  pixels  in  the  block  horizontally  and  vertically
  5112.        respectively. 
  5113.             
  5114.             Since the data  array  is  declared  as  integer  array, the
  5115.        number of bytes per line must be even. Since the length field can
  5116.        be any number,  that means some  of the  bits in the data  do not
  5117.        contain  useful  information.  In order to make  the program more
  5118.        efficient,  the starting bit of actual data  of each line  in the
  5119.        file is  the same  as that when  it is in  memory as part  of the
  5120.        frame.  x_offset is used to  store the starting  pixel number for
  5121.        the first word (2  byte) in each line. x_offset may contain value
  5122.        from 0 to 15. 
  5123.             
  5124.             The most significant bit of a byte is displayed  as the left
  5125.        most  pixel of the byte. The earlier bytes of the line are stored
  5126.        at the left of a  frame.  This is the same as Color  Graphics and
  5127.        Hercules Graphics.
  5128.  
  5129.  
  5130.  
  5131.  
  5132.  
  5133.  
  5134.  
  5135.  
  5136.  
  5137.  
  5138.  
  5139.  
  5140.  
  5141.                                      - 74 -
  5142.  
  5143.  
  5144.  
  5145.  
  5146.  
  5147.        GRAD User's Manual                                    June 7, 1987
  5148.  
  5149.        Appendix E : Functions Summary
  5150.  
  5151.        Function        Description
  5152.        Arc1            Draws arc (part of a circle)
  5153.        Arc2            Draws arc (part of a circle)
  5154.        ArcPoint        Gives 2 end points of Arc2 or Earc2
  5155.        BlockCopy       Copy a data block between 2 frames
  5156.        BlockLoad       Load a data block from disk
  5157.        BlockSave       Save a data block to disk
  5158.        Box             Draws a box
  5159.        calcaddr        Calculates the word address in byte of a point
  5160.        Circle          Draws a logical circle
  5161.        cleanup         Cleans up everything
  5162.        CopyBlock       Copys a block within or between frame(s)
  5163.        CreateFrame     Creates a new frame
  5164.        Dot             Draws a single dot
  5165.        Draw            Interprete a string of command
  5166.        Earc1           Draws arc (part of an ellipse)
  5167.        Earc2           Draws arc (part of an ellipse)
  5168.        Ellipse         Draws an ellipse
  5169.        EnvSave         Saves the environment
  5170.        EnvRsto         Restores the environment
  5171.        FillCircle      Draws a solid circle
  5172.        FillEllipse     Draws a solid ellipse
  5173.        fr_read         read a word
  5174.        fr_write        write a word according to plot type
  5175.        HorzLine        Draws a horizontal line of any width
  5176.        GRADinit        Initialize GRAD environment
  5177.        Line            Draws a line between any 2 points
  5178.        LoadFont        Loads a font file from disk
  5179.        NextXY          Gives next (x,y) location for ReadStr or WriteStr
  5180.        PatternFill     Fill the area by the pattern specified
  5181.        phyaddr         calculate physical address
  5182.        PlotType        Selects system plot type
  5183.        PrintFrame      Print a frame to Printer
  5184.        ReadStr         Read a line from standard input
  5185.        Rectangle       Draws a rectangle
  5186.        RelOrg          Set origin
  5187.        RemvFont        Removes a font from memory
  5188.        RemvFrame       Removes a frame from GRAD and release the memory
  5189.        ResetWin        Reset the window to the same size as the frame
  5190.        SelectFont      Selects the current font number
  5191.        SelectFrame     Selects the active frame
  5192.        SetOrg          Set origin
  5193.        SetStyle        Sets line style
  5194.        SetWin          Set a rectangular window
  5195.        SolidFill       Entirely fill a region
  5196.        VertLine        Draws a VertLine in any width
  5197.        writec          writes a single character
  5198.        writetype       set to over write
  5199.        WriteStr        writes a string
  5200.        XHLine          A horizontal line extends at both end
  5201.  
  5202.  
  5203.  
  5204.  
  5205.  
  5206.  
  5207.  
  5208.                                      - 75 -
  5209.  
  5210.  
  5211.  
  5212.  
  5213.  
  5214.        GRAD User's Manual                                    June 7, 1987
  5215.  
  5216.        Appendix F : System Limits
  5217.  
  5218.             There are two types of system limits. First type of limit is
  5219.        caused by  the compiler,  the  algorithms,  the  memory available
  5220.        ...etc.  If one  wants to change these limits,  a  lot of changes
  5221.        have to be made. Another kind of limit is just arbitrary. You may
  5222.        change these limits  by  changing  a constant  and re-compile the
  5223.        program provided you have the source codes, of course.
  5224.  
  5225.        
  5226.        Program Limits
  5227.  
  5228.        a. The  absolute  maximum physical  coordinate must be  less than
  5229.           +32767. In reality, physical coordinate can never get close to
  5230.           this number  because it is limited by  the maximum  frame size
  5231.           also.
  5232.  
  5233.        b. The range of  logical coordinate  must  be  within  -32768 and
  5234.           +32767.
  5235.  
  5236.        c. The maximum horizontal frame size is 4096. You may change this
  5237.           maximum by changing 2  or 3  modules but I think  4096 is more
  5238.           than enough in most cases.  The absolute maximum vertical size
  5239.           is 32767.  But you will run out of memory before you get close
  5240.           to this number.
  5241.  
  5242.        d. The  maximum length  of  the radius  for  Circle,  Arc1, Arc2,
  5243.           FillCircle must be less than 8192.
  5244.  
  5245.        e. For  Ellipse,  FillEllipse,  Earc1 and Earc2, square of one of
  5246.           the axes  times another axis  must  be less then  1E+9. If the
  5247.           length of both axis is the same, maximum length would be 1000.
  5248.           It should be sufficient for most  application except  when you
  5249.           are working on a high resolution output device such  as JLASER
  5250.           and you need a large ellipse.
  5251.  
  5252.        f. There are also limits on the length for HorzLine, VertLine and
  5253.           Line but they are limited by the frame size far before limited
  5254.           by the algorithm.
  5255.  
  5256.        
  5257.        Configuration Limits
  5258.  
  5259.        a. The maximum number of frame that can be exist at the same time
  5260.           including the default  frame  is  10.  This  is  controlled by
  5261.           NFRAME in source listing.
  5262.  
  5263.        b. The maximum number of font that can  be used at  the same time
  5264.           including the  font  in  ROM  is  10.  This  is  controlled by
  5265.           MAXNFONT in source listing.
  5266.  
  5267.        c. The  maximum number  of slot for saving  environment including
  5268.           slot 0 is 10. This is controlled by MAX_ENVSLOT.
  5269.  
  5270.        d. The maximum size of  a single character  is approximately 2000
  5271.           bytes.  That is about 120 by 120 pixels. This is controlled by
  5272.           the size of the array CFBUF.
  5273.  
  5274.  
  5275.                                      - 76 -
  5276.  
  5277.  
  5278.  
  5279.  
  5280.  
  5281.        GRAD User's Manual                                    June 7, 1987
  5282.  
  5283.        e. The maximum length of data on a single pass for the printer is
  5284.           2048  bytes.  This is also controlled by the size of the array
  5285.           CFBUF.
  5286.  
  5287.        f. There is no arbitrary limit on the length  of  string for draw
  5288.           and WriteStr except by the memory available and the compiler.
  5289.  
  5290.  
  5291.  
  5292.  
  5293.  
  5294.  
  5295.  
  5296.  
  5297.  
  5298.  
  5299.  
  5300.  
  5301.  
  5302.  
  5303.  
  5304.  
  5305.  
  5306.  
  5307.  
  5308.  
  5309.  
  5310.  
  5311.  
  5312.  
  5313.  
  5314.  
  5315.  
  5316.  
  5317.  
  5318.  
  5319.  
  5320.  
  5321.  
  5322.  
  5323.  
  5324.  
  5325.  
  5326.  
  5327.  
  5328.  
  5329.  
  5330.  
  5331.  
  5332.  
  5333.  
  5334.  
  5335.  
  5336.  
  5337.  
  5338.  
  5339.  
  5340.  
  5341.  
  5342.                                      - 77 -
  5343.  
  5344.  
  5345.  
  5346.  
  5347.  
  5348.        GRAD User's Manual                                    June 7, 1987
  5349.  
  5350.        Appendix G : Error Messages
  5351.  
  5352.             Below is  a list  of  all  possible  error  message  by GRAD
  5353.        functions.  In a strip down version of error handling routine, it
  5354.        may  only  print the error number.  So the error  number  is also
  5355.        given on the left of the message.
  5356.  
  5357.        Error no.
  5358.           0     "Undefined Error Number : %d"
  5359.           1     "invalid environment slot number in EnvSave - %d"
  5360.           2     "invalid environment slot number in EnvRsto - %d"
  5361.           3     "environment slot not used - %d"
  5362.           4     "disk access error in BlockSave"
  5363.           5     "bad block file"
  5364.           6     "file not found - %s"
  5365.           7     "too many frame opened"
  5366.           8     "not sufficient memory to create new frame - %d*%d"
  5367.           9     "insufficient stack size for Fill"
  5368.          10     "PROGRAM ERROR IN %s LINE %d"
  5369.          12     "bad font type - %d"
  5370.          13     "too many font files loaded"
  5371.          14     "bad font file"
  5372.          15     "not sufficient memory to load new font"
  5373.          16     "no more environment slot for Draw"
  5374.          17     "invalid command in Draw - %c%c"
  5375.          18     "wrong number of parameter given to %c%c in Draw"
  5376.          19     "a digit expected after '%' or '&' in Draw"
  5377.          20     "invalid marker number - %d"
  5378.          21     "disk error in reading font file"
  5379.  
  5380.  
  5381.  
  5382.  
  5383.  
  5384.  
  5385.  
  5386.  
  5387.  
  5388.  
  5389.  
  5390.  
  5391.  
  5392.  
  5393.  
  5394.  
  5395.  
  5396.  
  5397.  
  5398.  
  5399.  
  5400.  
  5401.  
  5402.  
  5403.  
  5404.  
  5405.  
  5406.  
  5407.  
  5408.  
  5409.                                      - 78 -
  5410.  
  5411.  
  5412.  
  5413.  
  5414.  
  5415.        GRAD User's Manual                                    June 7, 1987
  5416.  
  5417.        Appendix H : List of Header Files
  5418.  
  5419.             Below is the list of the header files for programs  that use
  5420.        the GRAD library.
  5421.  
  5422.        /*  GRADIO.H  */
  5423.        #define LEFT       0
  5424.        #define DOWN_LEFT  1
  5425.        #define DOWN       2
  5426.        #define DOWN_RIGHT 3
  5427.        #define RIGHT      4
  5428.        #define UP_RIGHT   5
  5429.        #define UP         6
  5430.        #define UP_LEFT    7
  5431.        #define BOTTOM_LEFT     0x00
  5432.        #define BOTTOM_CENTER   0x04
  5433.        #define BOTTOM_RIGHT    0x01
  5434.        #define TOP_LEFT        0x03
  5435.        #define TOP_CENTER      0x06
  5436.        #define TOP_RIGHT       0x02
  5437.        #define LEFT_CENTER     0x05
  5438.        #define RIGHT_CENTER    0x07
  5439.        #define CLEAR_CELL      0x10
  5440.        #define FILL_CELL       0x20
  5441.        #define INVERSE_CELL    0x30
  5442.        #define WRITE           0x00
  5443.        #define NO_WRITE        0x08
  5444.        #define AUTO_MOVE       0x0000
  5445.        #define FIX_MOVE        0x0100
  5446.        #define VAR_MOVE        0x0200
  5447.  
  5448.        /*  GRADARC.h  */
  5449.        #define UP_RIGHT 0x01
  5450.        #define RIGHT_UP 0x02
  5451.        #define RIGHT_DOWN 0x04
  5452.        #define DOWN_RIGHT 0x08
  5453.        #define DOWN_LEFT 0x10
  5454.        #define LEFT_DOWN 0x20
  5455.        #define LEFT_UP 0x40
  5456.        #define UP_LEFT 0x80
  5457.  
  5458.        #define UPPER_HALF 0xc3
  5459.        #define LOWER_HALF 0x3c
  5460.        #define LEFT_HALF 0xf0
  5461.        #define RIGHT_HALF 0x0f
  5462.  
  5463.        void Circle(), Arc1(), Arc2(), FillCircle();
  5464.        void Ellipse(), Earc1(), Earc2(), FillEllipse();
  5465.  
  5466.        /*  GRADENV.h  */
  5467.        int EnvSave(), EnvRsto();
  5468.  
  5469.        #define KEEP_SLOT     0x8000
  5470.        #define KEEP_WIN      0x0001
  5471.        #define KEEP_ORG      0x0002
  5472.        #define KEEP_STYLE    0x0004
  5473.        #define KEEP_PLOTTYPE 0x0008
  5474.        #define KEEP_FRAME    0x0010
  5475.  
  5476.                                      - 79 -
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.        GRAD User's Manual                                    June 7, 1987
  5483.  
  5484.        #define KEEP_FONT     0x0020
  5485.  
  5486.        /*  GRADVAR.h  */
  5487.        extern unsigned int DOTVALUE[];
  5488.        extern int XLIMIT, YLIMIT;
  5489.        extern int ORGX, ORGY;
  5490.        extern int TEN_MS;
  5491.        extern void (*PRE_ERROR_FUNC)(), (*POST_ERROR_FUNC)();
  5492.        extern int (*SPACING_FUNC)();
  5493.        extern int PRE_ERROR_LEVEL, POST_ERROR_LEVEL;
  5494.        extern int WINX1, WINX2, WINY1, WINY2;
  5495.  
  5496.  
  5497.  
  5498.  
  5499.  
  5500.  
  5501.  
  5502.  
  5503.  
  5504.  
  5505.  
  5506.  
  5507.  
  5508.  
  5509.  
  5510.  
  5511.  
  5512.  
  5513.  
  5514.  
  5515.  
  5516.  
  5517.  
  5518.  
  5519.  
  5520.  
  5521.  
  5522.  
  5523.  
  5524.  
  5525.  
  5526.  
  5527.  
  5528.  
  5529.  
  5530.  
  5531.  
  5532.  
  5533.  
  5534.  
  5535.  
  5536.  
  5537.  
  5538.  
  5539.  
  5540.  
  5541.  
  5542.  
  5543.                                      - 80 -
  5544.  
  5545.  
  5546.  
  5547.  
  5548.